One of the guys in IT manages a lot of Virtual Server instances, like dozens, adding up into many dozens of Virtual Machines all supporting our many devs. He wanted to get some status information with PowerShell. Here's what I came up with.
We used WMI Explorer to check out the WMI namespace installed by Virtual Server (root/vm/virtualserver).
Given a CSV file like this full of (at least) Virtual Server ComputerName
computername,owner,whateverMSVS1,fred,somedataMSVS2,joe,somedataMSVS3,luigi,somedata
We did this:
import-csv servers.csv | foreach-object { $_.computername } | foreach-object { Get-WmiObject -computername $_ -namespace "root/vm/virtualserver" -class VirtualMachine } | select @{Expression={"__SERVER"}; Name="Server"}, Name, CpuUtilization,select @{Expression={"Uptime/60"}; Name="Uptime(min)"}, PhysicalMemoryAllocated, DiskSpaceUsed | format-table -groupby Server -property name,CpuUtilization,Uptime,PhysicalMemoryAllocated,DiskSpaceUsed
Which gives us more or less this:
Which can also reformat, make smaller and run in a loop to get a "top" equivalent for all our VMs. We can catch machines that are running out of space, working too hard, and do capacity planning.
Note, I originally wanted to do this:
import-csv servers.csv | Get-WmiObject -namespace "root/vm/virtualserver" -class VirtualMachine
and have "computername" automatically bound to because the name was the same in the CSV file and the powershell parameter name. This does work in this instance...make a CSV file like this named pids.csv:
ID12345
and execute this PowerShell pipeline
import-csv pids.csv | get-process
and you'll get
Get-Process : No process with process ID 1 was found.At line:1 char:33+ import-csv pids.csv | get-process <<<<Get-Process : No process with process ID 2 was found.At line:1 char:33+ import-csv pids.csv | get-process <<<<Get-Process : No process with process ID 3 was found.At line:1 char:33+ import-csv pids.csv | get-process <<<< Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName------- ------ ----- ----- ----- ------ -- ----------- 2399 0 0 32 2 507.75 4 SystemGet-Process : No process with process ID 5 was found.At line:1 char:33+ import-csv pids.csv | get-process <<<<
Get-Process : No process with process ID 1 was found.At line:1 char:33+ import-csv pids.csv | get-process <<<<Get-Process : No process with process ID 2 was found.At line:1 char:33+ import-csv pids.csv | get-process <<<<Get-Process : No process with process ID 3 was found.At line:1 char:33+ import-csv pids.csv | get-process <<<<
Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName------- ------ ----- ----- ----- ------ -- ----------- 2399 0 0 32 2 507.75 4 SystemGet-Process : No process with process ID 5 was found.At line:1 char:33+ import-csv pids.csv | get-process <<<<
See how it called get-process for each ID and it automatically bound the ID column of the table coming from the CSV to the ID property? I wanted to do the same with with computername, but it didn't work.
Get-WmiObject : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.At line:1 char:21
I got this error which I assume means that Get-WMIObject doesn't take pipeline input in the build of PowerShell I have (RC1). I hope this is queued to get fixed ASAP or I'm just missing something.
UPDATE: A "help get-wmiobject" (duh, RTFM) confirms that -computername doesn't take pipeline input.
-ComputerName <System.String[]> Declares on which computer(s) the WMI object may be found
Parameter required? false Parameter position? named Parameter type System.String[] Default value localhost Accept multiple values? true Accepts pipeline input? false Accepts wildcard characters? false
Bummer.
Ads by The Lounge