Selecting Objects in PowerCLI
In PowerCLI, you can pass strings and wildcards to all parameters that take inventory objects, datastores, OSCustomizationSpec objects, and VIServer objects as arguments. This PowerCLI approach is named Object-by-Name (OBN) selection.
Instead of assigning an object name to a cmdlet parameter, users can pass the object through a pipeline or a variable. For example, the following three commands are interchangeable:
Remove-VM -VM "Win 7 SP1"
Get-VM -Name "Win 7 SP1" | Remove-VM
Remove-VM -VM (Get-VM -Name "Win 7 SP1")
If you provide a non-existing object name, an OBN failure occurs. In such cases, PowerCLI generates a non-terminating error and runs the cmdlet ignoring the invalid name.
For more details about OBN, run
An OBN failure
This example illustrates the occurrence of an OBN failure.
Set-VM –VM “VM1”, “VM2”, “VM3” –Server $server1, $server2 –MemoryGB 4
If the VM2 virtual machine does not exist on either of the selected servers, PowerCLI generates a non-terminating error and applies the command only on the VM1 and VM3 virtual machines.