Kumargtk
Contributor
Contributor

How to find Orphaned VMDK files

How can we find out Orphaned VMDK files in all the Data-stores.

111 Replies
LucD
Leadership
Leadership

You could do something like this

Get-Cluster -Name ProdA | Get-VMHost |
Get-Datastore -PipelineVariable ds | ForEach-Object -Process { 
    Remove-OrphanedData -Datastore $ds 
} | Export-Csv report.csv -NoTypeInformation -UseCulture


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

FSchleyhahn
Contributor
Contributor

Thank you.  That seems to be working.  What I think is happening is we have 2 datastores that are presented to every host in every cluster in our environment as they contain ISOs and Templates.  The names of these 2 datastores are as follows:

VM_MANAGEMENT_DATASTORE and vm_datastore_mgmt

Using the below statement, is there a way to inject code to EXCLUDE those 2 datastores?

Get-Cluster -Name ProdA | Get-VMHost | Get-Datastore -PipelineVariable ds | ForEach-Object -Process { Remove-OrphanedData -Datastore $ds } | Export-Csv report.csv -NoTypeInformation -UseCulture

0 Kudos
LucD
Leadership
Leadership

You could use a Where-clause.

Get-Cluster -Name ProdA | Get-VMHost |
Get-Datastore -PipelineVariable ds | 
where{'VM_MANAGEMENT_DATASTORE','vm_datastore_mgmt' -notcontains $_.Name} |
ForEach-Object -Process { 
    Remove-OrphanedData -Datastore $ds 
} | Export-Csv report.csv -NoTypeInformation -UseCulture


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

harezzebra1
Contributor
Contributor

Hi LucD,

 

I tried below script to find Orphaned VMDK in vSAN using https://www.lucd.info/2016/09/13/orphaned-files-revisited/

and changed line 67 to use type vSAN

if((($ds.Type -eq “VMFS”) -or ($ds.Type -eq “VSAN”)) -and $ds.ExtensionData.Summary.MultipleHostAccess -and $ds.State -eq “Available”) {

It's not giving any output, but I use RVtools I can see lots of Orphaned VMDK files.

Please help.

/s/Harshvardhan Gupta
0 Kudos
LucD
Leadership
Leadership

Did you give the script I attached in Solved: Re: get orphaned vmdk information from vSAN - VMware Technology Network VMTN a try?


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

0 Kudos
harezzebra1
Contributor
Contributor

Yes and tried running the verbose mode also-

Still getting error

Remove-OrphanedData -Datastore DEV_VSAN -Verbose
VERBOSE: 1/28/2021 2:50:40 PM Get-View Finished execution
VERBOSE: 1/28/2021 2:50:40 PM Get-Datastore Finished execution
VERBOSE: 1/28/2021 2:50:53 PM Get-VM Finished execution
VERBOSE: 1/28/2021 2:50:54 PM Get-Template Finished execution
VERBOSE: 1/28/2021 2:50:54 PM Get-View Finished execution
Exception calling "SearchDatastoreSubFolders" with "2" argument(s): "An error occurred while communicating with the remote host."
At line:72 char:17
+ ... $searchResult = $dsBrowser.SearchDatastoreSubFolders($roo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException

/s/Harshvardhan Gupta
0 Kudos
LucD
Leadership
Leadership

Is that with the modified script I linked to in my previous reply?


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

0 Kudos
harezzebra1
Contributor
Contributor

yes, I used the modified script for verbose output.

/s/Harshvardhan Gupta
0 Kudos
LucD
Leadership
Leadership

The error states "An error occurred while communicating with the remote host.", which has nothing to do with the script.
That seems to be an issue in your environment/setup.


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

0 Kudos
xsgao
Contributor
Contributor

DANDEROUS!!! I followed this find command and deleted my vmdk files completedly. I wish I can thumb down this post.

0 Kudos
xsgao
Contributor
Contributor

"You can easily find these orphaned vmdk’s via the Service Console / SSH from Putty:

find -iname “*-flat.vmdk” -mtime +7"

DANDEROUS!!! I followed this find command and deleted my vmdk files completely. I wish I can thumb down this post.

 

 

 

0 Kudos
LucD
Leadership
Leadership

The find command by itself will not delete any files, it will only list them.

But you are right, that just lists all VMDK, not only the orphaned ones.
That's where the script I posted comes in, it will check for each VMDK if it is connected to a VM or not.
And my script clearly states that you have to check the list of VMDK it produces, before actually deleting the files.


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

0 Kudos