Wednesday, July 18, 2012

Powershell and VMware: "Get the list of all Virtual machines on VMware VSphere Server using PowerCLI.

 

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"

18-07-2012 13-01-59 

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.

18-07-2012 13-06-21 

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 * 

18-07-2012 13-18-05 

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"}

18-07-2012 13-20-08 

Finally i got he list of all "Power ON " server and  i am happy now :)

 

Thanks for reading.

Thanks!

Aman Dhally

Buy-More-Twitter-Followers 4fb29548b6adc  linkedin

No comments:

Post a Comment