VMware

This Question is Answered

1 2 Previous Next 25 Replies Last post: Sep 10, 2009 12:20 AM by LucD   Go to original post

Re: How to list delta files in all datastores

15. Oct 14, 2008 10:58 AM in response to: Skark166
Click to view LucD's profile Champion 2,431 posts since
Oct 31, 2005
Add-Module is a cmdlet from PowerShell v2, and PowerShell 2 CTP2 is required for the VITK Community Extensions.
So that should be ok.

And I can't see anything wrong in the script.
Are you sure the Connect-VIServer is working ?
Do you see the "Name Port User" message in the output ?

Re: How to list delta files in all datastores

18. Oct 14, 2008 11:25 AM in response to: kastek
Click to view c_shanklin's profile Master 754 posts since
Dec 3, 2007
There is a scoping problem with the $defaultVIServer variable.

This is a workaround: in your script change:
Connect-VIServer -Server 192.168.xxx.xxx -User xxx -Password xxx


to
$server = Connect-VIServer -Server 192.168.xxx.xxx -User xxx -Password xxx
$global:defaultVIServer = $server


It seems there is something peculiar about script cmdlets that makes them run in a different context from other cmdlets. The way we populate and use $defaultVIServer is probably not helping.

Re: How to list delta files in all datastores

21. Oct 15, 2008 11:38 AM in response to: kastek
Click to view LucD's profile Champion 2,431 posts since
Oct 31, 2005
Sure, something I had lying around in my goodies chest ;-)

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"}
Attachments:

Re: How to list delta files in all datastores

23. Jul 20, 2009 1:34 PM in response to: c_shanklin
Click to view RS_1's profile Enthusiast 58 posts since
Nov 3, 2006

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

Thanks !

Attachments:

Re: How to list delta files in all datastores

24. Sep 9, 2009 11:31 PM in response to: c_shanklin
Click to view filip.hasa's profile Novice 9 posts since
Nov 26, 2007
Do you know how to get from command line? RCLI.

I cannot find it.

Thank you

Re: How to list delta files in all datastores

25. Sep 10, 2009 12:20 AM in response to: filip.hasa
Click to view LucD's profile Champion 2,431 posts since
Oct 31, 2005
That should normally be in the vifs.pl command but I'm afraid it doesn't allow masking nor recursive folder listings.

VMware Developer

SDKs, APIs, Videos, Learn and much more in the Developer community.

Learn More

Developer Sample Code

Increase your developer productivity with VMware API sample code.

Learn More

VMworld Sessions & Labs

Online access to the latest VMworld Sessions & Labs and online services.

Learn more

Purchase PSO Credits Online

Purchase credits to redeem training and consulting services online.

Buy Now

Community Hardware Software

View reported configurations or report your own.

Learn More

VMware vSphere

Come witness the next giant leap in virtualization.

Register Today

Communities