In my line of work we often evaluate new ways to do things, specifically new platforms for server hosting, disaster recovery, backups, etc.
One of the requests that often comes from vendors is “How big is your environment?”
Microsoft has the rather excellent “MAP” tool however I find it to be a bit slow, somewhat complex, and often returns a lot more information than I want… and not always everything I need.
To that end, I wrote the following powershell function and it has been a major help in automating these inventory requests:
FUNCTION GetSystemNames ($convention) {
$convention = "$convention" + "*"
Get-ADComputer -Filter {(Name -like $convention)}| select -ExpandProperty Name
}
FUNCTION GetSize($Servername) {
Invoke-Command -ScriptBlock {
$size = get-volume | Foreach { $_.Size }
$sumA = 0
$size | Foreach { $sumA += $_}
$size = [math]::Round($sumA/1GB,0)
$remaining = get-volume | ForEach {$_.SizeRemaining }
$sumB = 0
$remaining | Foreach { $sumB += $_}
$remaining = [math]::Round($sumB/1GB,0)
$usedspace = $size - $remaining
$usedspace = [math]::Round($usedspace,0)
$ram = gwmi Win32_OperatingSystem | Measure-Object -Property TotalVisibleMemorySize -Sum | % {[Math]::Round($_.sum/1024/1024)}
$CPUcores = Get-WmiObject Win32_Processor |Select-Object -ExpandProperty NumberOfCores
$CPUthreads = Get-WmiObject Win32_Processor |Select-Object -ExpandProperty NumberOfLogicalProcessors
$CPUname = Get-WmiObject Win32_Processor |Select-Object -ExpandProperty Name
$SystemType = get-wmiobject win32_computersystem | Select-Object -ExpandProperty model
$OSname = Get-WmiObject win32_operatingsystem | Select-Object -ExpandProperty caption
$out = "$size" + "`t" + "$usedspace" + "`t" + "$ram" + "`t" + "$CPUname" + "`t" + "$CPUcores" + "`t" + "$CPUthreads" + "`t" + "$SystemType" + "`t" + "$OSname"
$out
} -ComputerName $servername -ErrorAction SilentlyContinue
}
$output = @(GetSystemNames $ServerNamesStartWith)
#Can uncomment and modify below (change XYZ,ABC) to specify additional system naming conventions for the same run.
#$output += @(GetSystemNames XYZ)
#$output += @(GetSystemNames ABC)
$head = "SERVER" + "`t" + "STORAGE ALLOCATED" + "`t" + "STORAGE USED" + "`t" + "RAM" + "`t" + "CPU" + "`t" + "CORES" + "`t" + "THREADS" + "`t" + "SYSTEM" + "`t" + "OS"
$head
ForEach($name in $output) {
$size = GetSize $name
$info = "$name" + "`t" + "$size"
$info
}
}
After declaring the above function, I then run it and pipe the output like this:
Which then outputs a CSV file that looks something like this:
(NOTE: I have stripped/faked/anonymized data so I could post this publicly)
What the Script is Doing
Explanation of What Data is Pulled
Now the real beauty is in what gets pulled… Most of this is self-explanatory from the screenshot but I did want to explain a few items regardless..
Conclusion
For me, I pump this into excel and can quickly split out the physical and virtual systems, from there I can add up the “Storage Used” column and quite effortlessly know how big the data footprint is for my entire environment. That’s a key metric for lots of things… particularly platform hosting decisions, backups, disaster recovery, etc. I can also sort by processor type and pull down how many assigned vCORES I have of a given processor model… etc. etc. I find the barrier to entry and use SO much lower with this method vs. using the more expansive MAP tool and it has saved me a LOT of time. I hope it does the same for you!
Caveats