PowerShell for Windows Admins

May 7 2013   3:00PM GMT

Scripting Games-don’t repeat the work



Posted by: Richard Siddaway
Tags:
PowerShell
Scripting Games
WMI

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

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: