VMware Cloud Community
TDRoy
Enthusiast
Enthusiast
Jump to solution

Some help with Remove-VM

I have the following:

Get-Cluster 'xxx' | Get-VM | Select Name,

  @{N="ConnectionState";E={$_.ExtensionData.Runtime.ConnectionState}} |

  Where {$_.ConnectionState -eq "Orphaned"}

Im looking to pipe in a Remove-VM to this which will unregister any found orphaned VMs.

Im getting an error that it cannot take a pipe input.

Any assistance would be great

Thank you

Tags (1)
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The Remove-VM cmdlet expects a VirtualMachine object as input.

The object that is in the pipeline after the Select is not such an object.

Try like this

Get-Cluster 'xxx' | Get-VM |

Where {$_.ExtensionData.Runtime.ConnectionState -eq "Orphaned"} |

Remove-VM -Confirm:$false


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

View solution in original post

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

The Remove-VM cmdlet expects a VirtualMachine object as input.

The object that is in the pipeline after the Select is not such an object.

Try like this

Get-Cluster 'xxx' | Get-VM |

Where {$_.ExtensionData.Runtime.ConnectionState -eq "Orphaned"} |

Remove-VM -Confirm:$false


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

Reply
0 Kudos
TDRoy
Enthusiast
Enthusiast
Jump to solution

Hi Luc,

**Edit** It does work. I was running this in a weird older version of PS or PCLI and it was erroring out.

Thank you

Reply
0 Kudos