Delete VMDK file with powershell/powercli command?

697 views Asked by At

I'm a little bit stuck because I would like to delete some VMDK file from vSphere with a PowerShell or PowerCLI command.

I know how to do that from the vSphere vCenter GUI but I didn't find how to do that with a command.

Do you think that there is a way to do that with something like:

Remove-Item path/to/my/VMDK

If someone has already made this, can you show me how?

2

There are 2 answers

0
Kyle Ruddy On

You could use the vmstores PSDrive option that will allow you to use standard PowerShell functionalities alongside an authenticated vSphere session.

Example of polling your available datastores:

dir -Recurse -Path vmstores:\

Additional info: Browse datastores using PowerCLI

0
NickMartin On

You can also remove the vmdk file with the powercli Remove-Harddisk cmdlet (with -DeletePermanently you physically remove the vmdk from the datastore).