Reply to Message

View discussion in a popup

Replying to:
LucD
Leadership
Leadership

Yes, you can, provided they are in different folders.
Same goes for VMs.

You can select a specific VM by adding for example the folder.

 

Get-Folder -Name MyFolder | Get-VM -Name MyVM

 

If you are using Get-View, you can use the Folder as the value for the SearchRoot parameter.

 

$folder = Get-Folder -Name 'MyFolder'
Get-View -ViewType VirtualMachine -SearchRoot $folder.Id -Filter @{Name='MyVM'}

 


Another option is to use something like my Get-VIObjectByPath function.
Just be aware that it returns a vSphere object (the same as what Get-View returns).
To convert that to a .NET object you will need to use the 

 

$obj = Get-VIObjectByPath -Path 'MyDatacenter/MyFolder/MyVM'

$vmView = $obj.Node
$vm = Get-VIObjectByVIView -VIView $obj.Node

 

 


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos