Retrieving a list of all of your virtual machines

Now that we know how to connect to a server, let's do something useful with PowerCLI. Most of the people who begin using PowerCLI create reports, so create a list of all of your virtual machines as your first report. You have to use the Get-VM cmdlet to retrieve a list of your virtual machines. The syntax of the Get-VM cmdlet is as follows. The first parameter set is the default:

Get-VM [[-Name] <String[]>] [-Server <VIServer[]>] 
    [-Datastore <StorageResource[]>] [-Location <VIContainer[]>]
    [-Tag <Tag[]>] [-NoRecursion] [<CommonParameters>]

The second parameter set is for retrieving virtual machines connected to specific virtual switches:

Get-VM [[-Name] <String[]>] [-Server <VIServer[]>] [-VirtualSwitch ...

Get Learning PowerCLI - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.