You can pass strings and wildcards to all parameters that take inventory objects, datastores, OSCustomizationSpec objects, and VIServer objects as arguments. PowerCLI then transforms the strings into PowerShell objects. This approach is called Object-by-Name (OBN) selection.
Using OBN
For example, if you pass Start-VM -VM "myVM"
, PowerCLI trasforms the string parameter, "myVM", into a PowerShell object. This is how OBN works.
For more details about OBN, run help about_OBN
.
Using pipelines and variables
Instead of assigning an object name to a cmdlet parameter, you 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")
An OBN failure
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.
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.