Here is the script mentioned above:
write-host (Get-Date).TimeOfDay Getting datastores...
$dss = get-datastore
write-host (Get-Date).TimeOfDay $dss.Count datastores found
$fqf = New-Object VMware.Vim.FileQueryFlags
$fqf.FileSize = $true
$fqf.FileType = $true
$fqf.Modification = $true
$fqf.FileOwner = $true
$fq1 = New-Object VMware.Vim.FileQuery
$ss1 = New-Object VMware.Vim.HostDatastoreBrowserSearchSpec
$ss1.details = $fqf
$ss1.sortFoldersFirst = $true
$ss1.MatchPattern += "*.*"
$ss2 = New-Object VMware.Vim.HostDatastoreBrowserSearchSpec
$ss2.details = $fqf
$ss2.sortFoldersFirst = $true
$ss2.MatchPattern += "*delta.vmdk"
$ss2.MatchPattern += "*flat.vmdk"
$ss1.Query = $fq1
foreach($ds in $dss)
{
$dsv = $ds | get-view
if($ds.Accessible -ne $true)
{
write-host (Get-Date).TimeOfDay Skip files collecting because $dsv.Summary.Name"("$dsv.Summary.Datastore.Value")" is not accessible.
}
else
{
$dsb = get-view $dsv.browser
$rp = "["+$dsv.summary.Name+"]"
write-host (Get-Date).TimeOfDay Trying to collect *.vmdk and *.flat files from $dsv.Summary.Name"("$dsv.Summary.Datastore.Value")"
$sr2 = $dsb.SearchDatastoreSubFolders($rp, $ss2)
write-host (Get-Date).TimeOfDay Completed. $sr2.Count files found on $dsv.Summary.Name"("$dsv.Summary.Datastore.Value")"
write-host (Get-Date).TimeOfDay Trying to collect other files from $dsv.Summary.Name"("$dsv.Summary.Datastore.Value")"
$sr1 = $dsb.SearchDatastoreSubFolders($rp, $ss1)
write-host (Get-Date).TimeOfDay Completed. $sr1.Count files found on $dsv.Summary.Name"("$dsv.Summary.Datastore.Value")"
}
}