VMware Cloud Community
vmSpecDaniel
Enthusiast
Enthusiast
Jump to solution

PowerCLI - How to distinguish real vm from SRM placeholder

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?

1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

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'}

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

3 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

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'}

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
vmSpecDaniel
Enthusiast
Enthusiast
Jump to solution

This is correct, thanks.

0 Kudos
admin
Immortal
Immortal
Jump to solution

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*"}

0 Kudos