VMware Cloud Community
omar13489
Contributor
Contributor

How to find Orphaned VMDK files with -Delete Option

Hi LucD,

After our discussion, I need to update the attached script that finds all the ESX Orphaned Files

You wrote the script to find only the Orphaned Files within the Data-stores without deleting them

Can you provide an updated Script that Find all the Orphaned Files and Give the user the -Delete Option ?

Something like this : Orphaned files and folders - Spring cleaning - LucD notes

Thanks in Advance

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership

Try with the attached new version.

You can now do

Get-Datastore -Name DS1 | Get-VmwOrphan -Delete -WhatIf

Once you are sure the correct files will be removed, you can drop the WhatIf switch.

I added an additional parameter ExcludeFolder, which is jandy if you to want speficic folders on the datastore (ISO folder, snapshot folder...)

You can use it like

Get-Datastore -Name DS1 | Get-VmwOrphan -ExcludeFolder 'Folder1','Folder2'

And finally a PS, sometimes you will need to call the function at least twice.
When an orphaned folder contains and orphaned file, the 1st run will remove the file, the 2nd run will remove the folder.


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

Reply
0 Kudos
omar13489
Contributor
Contributor

Thank you a lot,

I will check the script and update you with the results as soon as possible

Reply
0 Kudos
vmCalgary
Enthusiast
Enthusiast

LucD,

I read through the comments in your spring cleaning script. I admit it, I got lost when it came to altering the script for an NFS environment.

Do you have a copy of your script that returns results for an NFS environment?

 

Reply
0 Kudos
LucD
Leadership
Leadership

It should be just changing

if($ds.Type -eq "VMFS" -and $ds.ExtensionData.Summary.MultipleHostAccess){

into

if($ds.ExtensionData.Summary.MultipleHostAccess){


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

Reply
0 Kudos