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
Try like this.
Remove the WhatIf when you are sure the correct VMs are being unregistered
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
Try like this.
Remove the WhatIf when you are sure the correct VMs are being unregistered
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
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
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
OK, I am going to carve out a separate datastore and destroyable VM's in it and test this.