How can we find out Orphaned VMDK files in all the Data-stores.
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
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
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
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.
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
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
Is that with the modified script I linked to in my previous reply?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
yes, I used the modified script for verbose output.
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
DANDEROUS!!! I followed this find command and deleted my vmdk files completedly. I wish I can thumb down this post.
"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.
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
I noted that this thread has been quiet for a while. Does the script work with a v7U3 setup?
I have 2 hosts (used for DR) that have their own storage (not vSAN)
I have the script function loaded - login to vCenter OK can see the datastores OK
Running the function gives no output - not even the "not found" message just returns to the PS prompt.
@LucD Is there by chance an updated version of this script compatible with vSphere 7.0.3 or maybe some other tool (free or paid) that can produce similar results? In the same boat as Avon where the script won't produce and results.
I'll do some more test.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Did you already try changing line 42 to
if ($ds.Type -eq "VMFS") {
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
@LucD I changed the following in line 42:
if($ds.Type -eq "VMFS" -and $ds.ExtensionData.Summary.MultipleHostAccess -and $ds.Accessible){
to
if ($ds.Type -eq "VMFS") {
Script does now run but only provides a few lines for information pertaining to 3 of the 4 ESXi hosts in our cluster. (Spreadsheet attached).
I think I read previously that this may not work with vSAN, is that still the case?
Why did you change it to
if($ds.GetType().Name -eq "String"){
A Datastore object will never equal a String.
I advised to just leave out the MultiHostAccess test.
Are your datastores not VMFS datastores?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
@LucD My apologies, I copied the line info for Line 37, not 42. Line 42 in my script is set to:
if ($ds.Type -eq "VMFS") {
I modified my previous post to reflect the correct information in line 42.
I posted a VSAN compatible version in thisanother thread, see Solved: Re: get orphaned vmdk information from vSAN - VMware Technology Network VMTN
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference