Kumargtk
Contributor
Contributor

How to find Orphaned VMDK files

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

109 Replies
FSchleyhahn
Contributor
Contributor

I have run the script to produce the report.csv for ALL of the datastores within my virtual center, but unfortunately, because of the massive volume of datastores, the script keeps timing out.  It produces about 500 lines within the report and that's it.  Is it possible to run this script per cluster and if so, what would the syntax be?  For example, one of the clusters is named "ProdA".  How would I run this script for ONLY the datastores presented to the ProdA Cluster?

 

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

0 Kudos
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