VMware Cloud Community
COS
Expert
Expert
Jump to solution

Get list of registered VM's that are in my test datastore then unregister them

I have a test datastore called "test-vmgarbage-nobackups".

How can I get a list of VM's that are registered in vCenter that live on my test datastore then unregister them from vCenter?

NOTE: there are some VM's that have disks on that datastore but the vmx file resides on another datastore. I don't want to touch those.

Thanks

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this.
Remove the WhatIf when you are sure the correct VMs are being unregistered

$dsName = 'MyDS'

Get-VM -Datastore $dsName |

   where {$_.ExtensionData.Summary.Config.VmPathName -match $dsName} |

   Remove-VM -DeletePermanently:$false -Confirm:$false -WhatIf


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

View solution in original post

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

Try like this.
Remove the WhatIf when you are sure the correct VMs are being unregistered

$dsName = 'MyDS'

Get-VM -Datastore $dsName |

   where {$_.ExtensionData.Summary.Config.VmPathName -match $dsName} |

   Remove-VM -DeletePermanently:$false -Confirm:$false -WhatIf


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

Reply
0 Kudos
COS
Expert
Expert
Jump to solution

This line scares me.....

"Remove-VM -DeletePermanently:$false -Confirm:$false -WhatIf"

Specifically "-DeletePermanently" because it's defined as.....

Indicate that you want to delete the virtual machines not only from the inventory, but from the datastore.

:smileyshocked:

Ultimately I will be registering the VM's to another vcenter server that is also attached to this datastore then rmove the datastore from the old vcenter server.

Thanks

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That's why the $false is on there.
We do NOT want to remove the file, just unregister the VM.

You can leave that parameter out, but I prefer to see what I'm doing
Also avoids issues if someone has set DefaultParameters


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

Reply
0 Kudos
COS
Expert
Expert
Jump to solution

OK, I am going to carve out a separate datastore and destroyable VM's in it and test this.

Smiley Happy

Reply
0 Kudos