That worked, thank you.
Original Message:
Sent: Nov 06, 2024 03:42 PM
From: LucD
Subject: Add a filter on get-view to only return results from a specific cluster
You can use the Server parameter on the Get-Cluster cmdlet
Get-View -ViewType VirtualMachine -SearchRoot ((Get-Cluster -Name MyCluster -Server MyvCenter).ExtensionData.MoRef) -Property Parent, Config, Summary, Runtime
------------------------------
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Original Message:
Sent: Nov 06, 2024 03:09 PM
From: dbutch1976
Subject: Add a filter on get-view to only return results from a specific cluster
Thanks LucD, works great, however I'm still having an issue with my results. It appears that there are many VMs which are replicated, so I believe that may be why I'm getting results from multiple vCenters like this:
Name: MyVM
Cluster : {MYCLUSTERDR, MYCLUSTER, MYCLUSTER3}
When exported to csv the field simply says System.Object[]
Can I and an additional qualifier to -SearchRoot ? Something like -SearchRoot ((Get-Cluster -Name MyCluster).ExtensionData.MoRef) -and ([uri]$_.Client.ServiceUrl).MYVCENTER ?
The goal would be to further isolate my results to one vCenter while remaining connected to all of them.
Original Message:
Sent: Nov 06, 2024 01:59 PM
From: LucD
Subject: Add a filter on get-view to only return results from a specific cluster
Use the SearchRoot parameter instead.
Get-View -ViewType VirtualMachine -SearchRoot ((Get-Cluster -Name MyCluster).ExtensionData.MoRef) -Property Parent, Config, Summary, Runtime
------------------------------
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Original Message:
Sent: Nov 06, 2024 12:42 PM
From: dbutch1976
Subject: Add a filter on get-view to only return results from a specific cluster
Hi All,
I've had some luck using get-filter to filter on individual VMs by name, but how can I use get-view -filter to only return results from a specific cluster?
Get-View -ViewType VirtualMachine -Filter @{"Cluster"="ndh1-pod3-compute1"} -Property Parent, Config, Summary, Runtime |
ForEach-Object -Process {
$esx = Get-View -Id $_.Runtime.Host -Property Name, Parent
[PSCustomObject] @{
Name = $_.config.name
GuestId = $_.Config.GuestId
vCenter = ([uri]$_.Client.ServiceUrl).Host
Folder = (Get-View -Id $_.Parent -Property Name).Name
'IP Address' = $_.Summary.Guest.IpAddress
Template = $_.summary.config.Template
VMHost = $esx.Name
Cluster = (Get-View -Id $esx.Parent -Property Name).Name
Notes = $_.summary.config.annotation
}
}
This is erroring out.