Enthusiast
Enthusiast

run get-view for a specific list of vmguests

Jump to solution

I am using this command to pull specific properties from all the vmguests in vCenter.

$vms = Get-View -Server $vcenter -ViewType VirtualMachine -Property Name,Config,Snapshot,Summary,CustomValue,Guest,Runtime.Host,AvailableField,Value,Parent

I want to use the same command against a specific list of vmguests listed in a text file. I don't want to use Get-VM because it's too slow.

So I tried something like this, but it's not working.

$computers = Get-Content "$PSScriptRoot\computers.txt"

$vms = Get-View -Filter @{"Name" = $computers} -Server $vcenter -ViewType VirtualMachine -Property Name,Config,Snapshot,Summary,CustomValue,Guest,Runtime.Host,AvailableField,Value,Parent

How can I run the Get-View command against a specific list of vmguests?

Thanks

0 Kudos
1 Solution

Accepted Solutions
Leadership
Leadership

The right side value of each line in the Filter parameter, shall be a RegEx expression.

So assuming you have multiple VM names, one per line in the file, you have to separate them with the RegEx OR symbol '|'

Try like this (btw I used splatting to make the long lines more legible)

$computers = (Get-Content "$PSScriptRoot\computers.txt"  ) -join '|'

$sView = @{

   Filter = @{"Name" = $computers}

   Server = $vcenter

   ViewType = 'VirtualMachine'

   Property = 'Name','Config','Snapshot','Summary','CustomValue',

     'Guest','Runtime.Host','AvailableField','Value','Parent'

}

$vms = Get-View @sView

---------------------------------------------------------------------------------------------------------

Was it helpful? Let us know by completing this short survey here.


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

View solution in original post

0 Kudos
2 Replies
Leadership
Leadership

The right side value of each line in the Filter parameter, shall be a RegEx expression.

So assuming you have multiple VM names, one per line in the file, you have to separate them with the RegEx OR symbol '|'

Try like this (btw I used splatting to make the long lines more legible)

$computers = (Get-Content "$PSScriptRoot\computers.txt"  ) -join '|'

$sView = @{

   Filter = @{"Name" = $computers}

   Server = $vcenter

   ViewType = 'VirtualMachine'

   Property = 'Name','Config','Snapshot','Summary','CustomValue',

     'Guest','Runtime.Host','AvailableField','Value','Parent'

}

$vms = Get-View @sView

---------------------------------------------------------------------------------------------------------

Was it helpful? Let us know by completing this short survey here.


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

View solution in original post

0 Kudos
Enthusiast
Enthusiast

worked like a charm. good info. Thank  you very much!

0 Kudos