VMware Cloud Community
rpmfx
Contributor
Contributor
Jump to solution

Deleting Specific Folders from Specific Datastore

Hey all,

I have a script that I'm working on that occasionally leaves behind some orphaned VMDKs from a previous clone operation in a previous run of the script. I was wondering what would be the best way to target and remove a specific folder from a specific datastore so that I can incorporate it into my script. If I don't remove the orphaned folder before a future script run, the script will try to use the old VMDKs instead of the ones from the new clone operation. Any help would be amazing! I tried searching a bit and didn't quite come across something that suited my needs or that I could piece together myself from a snippet in an existing script on here.

Thanks!

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

If you have the path to the orphaned VMDK, you could use the Datastore Provider.

Once mapped, you can use (most of) the regular filesystem cmdlets (like Remove-Item).

See for example Re: Finding the last modified date for Orphaned vmdk file

where I used the New-PSDrive to map a datastore, and then was able to use Get-ChildItem to search the filesystem.


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

If you have the path to the orphaned VMDK, you could use the Datastore Provider.

Once mapped, you can use (most of) the regular filesystem cmdlets (like Remove-Item).

See for example Re: Finding the last modified date for Orphaned vmdk file

where I used the New-PSDrive to map a datastore, and then was able to use Get-ChildItem to search the filesystem.


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

0 Kudos
rpmfx
Contributor
Contributor
Jump to solution

This looks like a great solution to what I am looking for so I will give it a shot. Thank you!

0 Kudos