VMware Cloud Community
kastek
Contributor
Contributor
Jump to solution

How to list delta files in all datastores

I've recently found the VI Toolkit and have learned a lot from these forums.

I'd like to be able to search the contents of all datastores for the existence of any delta files, indicating the presence of lingering snapshots...old or new.

I'd like to see the paths, filenames, sizes and dates of any delta files.

Can anyone point me in the right direction?

Thank you...Mike

Tags (3)
Reply
0 Kudos
25 Replies
kastek
Contributor
Contributor
Jump to solution

Des anyone have a method to search all datastores for "delta" files, without using the VI Toolkit Community Extensions?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sure, something I had lying around in my goodies chest Smiley Wink

function Get-DatastoreDir ($DSName){

  $dsImpl = Get-Datastore -Name $DSName
  $ds = Get-Datastore -Name $DSName | Get-View
  $dsBrowser = Get-View -Id $ds.Browser

  $datastorepath = "[http://" + $ds.Summary.Name + "|http://" + $ds.Summary.Name + "]"
  
  $searchspec = New-Object VMware.Vim.HostDatastoreBrowserSearchSpec
  $searchSpec.matchpattern = "*"
  $searchSpec.details = New-Object VMware.Vim.FileQueryFlags
  $searchSpec.details.fileSize = $true
  $searchSpec.details.fileType = $true
  $searchSpec.details.modification = $true
 
  $taskMoRef = $dsBrowser.SearchDatastoreSubFolders_Task($datastorePath, $searchSpec) 
  $task = Get-View $taskMoRef 
  while ($task.Info.State -eq "running"){$task = Get-View $taskMoRef}

  $report = @() 
  foreach ($result in $task.info.Result){
    foreach($file in $result.File){
      if($file.GetType().Name -ne "FolderFileInfo"){
	    $row = "" | Select Filename, Folder, Filesize, Modification
        $row.Filename = $file.Path
	    $row.Folder = $result.FolderPath
	    $row.Filesize = $file.FileSize
	    $row.Modification = $file.Modification
	    $report += $row
	  }
    }
  }
  $report
}

Get-DatastoreDir <datastore-name> | Where-Object {$_.Filename -match "flat"}

If you want to do this for all your datastores you could change the last line to

Get-Datastore | %{Get-DatastoreDir $_.Name} | Where-Object {$_.Filename -match "flat"}


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

kastek
Contributor
Contributor
Jump to solution

That did it..perfectly...thank you very, very much!

Reply
0 Kudos
RS_1
Enthusiast
Enthusiast
Jump to solution

@c_shanklin : your workaround works for me (i got the "You are not currently connected..." case too)

Thanks !

Reply
0 Kudos
filip_hasa
Contributor
Contributor
Jump to solution

Do you know how to get from command line? RCLI.

I cannot find it.

Thank you

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That should normally be in the vifs.pl command but I'm afraid it doesn't allow masking nor recursive folder listings.


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

Reply
0 Kudos