Use PowerCLI to get quick stats

Sometimes you just want to get an at-a-glance view of your VMware environment. With PowerCLI, getting some down and dirty statistics is quite simple. First, you need to get PowerCLI, which is VMware’s PowerShell-based command line tool.

Once you have the tool installed, start a PowerCLI command prompt and execute the command:

set-executionpolicy remotesigned

This command configured PowerCLI to run local scripts without hassling you but requires that scripts downloaded from the Internet be signed by a trusted publisher. If you don’t execute this command, you will get errors in PowerCLI.

Next, connect to your vSphere server using the Connect-VIserver cmdlet. You need to specify the name or IP address of your vSphere server, the connections protocol – HTTP or HTTPS – and the username and password for a user with enough rights to poll the server for statistics. For my lab server, I use the following command:

Connect-VIServer -Server 192.168.200.1 -Protocol https -User root -Password password

If the connection is successful, you will be presented with information about the connection.

Figure 1 – Connection successful

Now, to obtain a list of virtual machines running on this server, execute the get-vm command. For more detailed information about each virtual machine, execute get-vm | fl. You can see in the next two figures that I have just one virtual machine running on this host right now and that it is in a powered on state. The fl command tells PowerCLI to format the resulting output as a list, the results of which are shown in Figure 3.

Figure 2 – The results of get-vm

Figure 3 – The results of get-vm | fl

The final cmdlet that I’ll brief you on in this posting is get-vmguest. This cmdlet requires that you specify the name of a virtual machine and returns some state information about that particular virtual machine including the current operating system, run state, host name and screen dimensions. You can see in Figure 4 that I’ve used the command get-vmguest Win7-USB | fl to return information about the virtual machine name Win7-USB.

Figure 4 – The results of get-vmguest Win7-USB | fl

Summary

This is not the last time I’ll be talking about PowerCLI in the column. In fact, I intend to discuss it in much more depth over time.

Follow me on Twitter: @otherscottlowe

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top