HI,
In my first post about “Getting Started with VMware Vshpere PowerCLI” i already showed how to connect with VMware server.
Our today’s task is simple. you get the list of all Virtual machines, and then we search for all “Powered ON” machines and after that all “Power off” machines.
Nothing complicated here. this is just a simple task and again the basic usage of Powershell is applies here. and we have some good “best friend ” cmdlets those always with us. these cmdlets are “where-Object”, “Select-Object”.
Let’s Start
Connect to your VMware server first using Connect-VIServer cmdlet. Once you successfully connected.
Run the Get-VM cmdlet.
That will show you the list of all Virtual machines including their “Power State”
If you want to see all the properties of Virtual Machines, run the below cmdlet.
Get-VM | Format-List *
Now you can see that we have detailed information about virtual machines.
And in case you want to know about a single Virtual Machine , use Get-Vm and -Name of the machine and then Piped it to fl *
Get-Vm -Name “Dummy-Windows7” | fl *
As i mentioned in the starting that our original target is to find the list of all Up and Running Virtual machines. To achieve that we can use Where-Object and show that Virtual machines whose status is equal to “Powered ON”.
Get-vm | where { $_.PowerState -eq “PoweredOn”}
Thanks for reading.
Thanks!
Aman Dhally



Why does it give you more information when you try to save it out as a report ?
When saving to a report running Get-vm | where { $_.PowerState -eq “PoweredOn”} | ConvertTo-HTML |Out-File C:\scripts\poweredonreport.htm
When running it to output to file I would get:
powerstate, version, description, notes, guest, numCPU, Memory<B, Hard disks etc.. etc..
I just want the same info you would get when running it from powercli command line.
Hi,
You can use the Select-Object cmdlet to choose which Attribute and its value you wants in the output.
something like
Get-vm | where { $_.PowerState -eq “PoweredOn”} | select powerstate, version, description | ConvertTo-HTML | Out-File C:\scripts\poweredonreport.htm
Thanks
Aman
Hi,
Is it possible to get list of powered off VM via script from multiple vcenter and on email ?
Thanks in advance !!
Hi BS,
Yes it is possible to get list of powwerd off VM via script from multiple vcenter on email.
unfortunately, i don’t have any ready-made script for the same.
Thanks
Aman
Somebody Knows how Can I get a List of virtual machines depend on folder where live each one… I dont know if exists something like -path or -searchbase in POWERCLI
Hi,
how do i get specific task details for all vms like backup status by powercli