Quantcast
Channel: WMI – PowerShell for Windows Admins
Viewing all articles
Browse latest Browse all 140

Scripting Games-don’t repeat the work

$
0
0

There are some good features to this script but what really hurts is the two trips to the server for the Win32_Computersystem class

Foreach ($IP in (Get-Content “C:\IPList.txt”))
{
$Name = (Get-WMIObject Win32_ComputerSystem -ComputerName $ip).Name
$Mem = [math]::truncate((Get-WMIObject Win32_ComputerSystem -ComputerName $ip).TotalPhysicalMemory / 1MB)
$Ver = (Get-WMIObject Win32_OperatingSystem -ComputerName $ip).Caption
[Array]$Cpus = (Get-WMIObject Win32_Processor -ComputerName $ip)
$CpuCount = $Cpus.Count
$Cores = 0
Foreach ($Socket in $Cpus)
{
$Cores = $Cores + $Socket.NumberOfCores
}
“$Name,$Mem,$Ver,$CpuCount,$Cores” | Out-File output.csv -Append
}
it would be better to do this
$comp = Get-WMIObject Win32_ComputerSystem -ComputerName $ip
$name = $comp.Name
$mem = [math]::truncate($comp.TotalPhysicalMemory / 1MB)

Dropping one round trip on a few servers isn’t that big a deal. dropping it on 3000 servers will make a difference
Always think about how your scripts may need to scale one day


Viewing all articles
Browse latest Browse all 140

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>