The five best Windows PowerShell v3 commands every admin should know


Running the Invoke-Command cmdlet for bulk operations

The Invoke-Command cmdlet performs bulk PowerShell operations against multiple targets. This allows you to more easily manage large numbers of VMs because you can run the cmdlet against multiple Hyper-V hosts. Simply include the –ComputerName switch with the names of the target servers separated by commas and the command that you want to run on the remote servers enclosed in braces.

Suppose for a moment that you want to retrieve the name, state and status of all VMs running on servers named Lab1 and Lab2. You could accomplish this task with the following PowerShell v3 command:

Invoke-Command –ComputerName Lab1, Lab2 {Get-VM | FT VMName, State, PrimaryStatusDescription}

The image shows an example of this command. As you can see, the Invoke-Command directs the Get-VM command at multiple Hyper-V hosts. It also retrieves specific attributes for each VM by specifying those that should be displayed.

View All Photo Stories