Hi,
I'm using PowerCLI to list all vm that are in my vCenter but I'm getting double record for some of the vm's.
I checked in vCenter and found that what I'm getting are real vm's and SRM placeholders on the same list, how can I distinguish real vm from SRM placeholder in PowerCLI?
To retrieve all of the virtual machines that are not SRM placeholders, you can use the following PowerCLI command:
Get-VM | Where-Object {$_.ExtensionData.Config.ManagedBy.ExtensionKey -ne 'com.vmware.vcDr'}
To retrieve only the SRM placeholders virtual machines, you can use the following PowerCLI command:
Get-VM | Where-Object {$_.ExtensionData.Config.ManagedBy.ExtensionKey -eq 'com.vmware.vcDr'}
To retrieve all of the virtual machines that are not SRM placeholders, you can use the following PowerCLI command:
Get-VM | Where-Object {$_.ExtensionData.Config.ManagedBy.ExtensionKey -ne 'com.vmware.vcDr'}
To retrieve only the SRM placeholders virtual machines, you can use the following PowerCLI command:
Get-VM | Where-Object {$_.ExtensionData.Config.ManagedBy.ExtensionKey -eq 'com.vmware.vcDr'}
This is correct, thanks.
These queries will work most of the time, it will have a couple of issues if you are using an N:1 deployment (or custom srm-id) and will treat "test" VMs as placeholders which may or may not be what you want.
Below are my suggestions.
Retrieve placeholder VMs:
Get-VM | where {$_.ExtensionData.Config.ManagedBy.extensionKey -like "com.vmware.vcDr*" -and $_.ExtensionData.Config.ManagedBy.Type -ieq 'placeholderVm'}
Retrieve test VMs:
Get-VM | where {$_.ExtensionData.Config.ManagedBy.extensionKey -like "com.vmware.vcDr*" -and $_.ExtensionData.Config.ManagedBy.Type -ieq 'testVm'}
Retrieve non-SRM managed VMs (excludes both placeholder and test VMs):
Get-VM | where {$_.ExtensionData.Config.ManagedBy.extensionKey -NotLike "com.vmware.vcDr*"}