How can I get the filesize of a specific file on a VMFS?
Something like: \[datastore1\]/folder1/file1
I tried around with "SearchDatastoreSubFolders" but I didn't found a way. I found some examples, but they all list all files on the datastore.
Daniel
Have a look at .
In the script I wrote for that thread you could change the matchpattern property of the HostDatastoreBrowserSearchSpec object to contain the name of the file for which you want to know the size.
... $searchSpec.matchpattern = "file1" ...
Another option is to get all files in the folder ("\[datastore1\]/folder1" and then use a loop to find the specific file you are looking for.
... foreach ($result in $task.info.Result){ foreach($file in $result.File){ if($file.Path -eq "file1"){ $file.Path $file.fileSize } } }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Have a look at .
In the script I wrote for that thread you could change the matchpattern property of the HostDatastoreBrowserSearchSpec object to contain the name of the file for which you want to know the size.
... $searchSpec.matchpattern = "file1" ...
Another option is to get all files in the folder ("\[datastore1\]/folder1" and then use a loop to find the specific file you are looking for.
... foreach ($result in $task.info.Result){ foreach($file in $result.File){ if($file.Path -eq "file1"){ $file.Path $file.fileSize } } }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you LucD, this was very helpful. I modified your code and it works as expected:
$DSName = "VMFS_01" $sPattern = "*delta.vmdk" $ds = Get-Datastore -Name $DSName | Get-View $dsBrowser = Get-View -Id $ds.Browser $datastorepath = "" $searchspec = New-Object VMware.Vim.HostDatastoreBrowserSearchSpec $searchSpec.matchpattern = $sPattern $searchSpec.details = New-Object VMware.Vim.FileQueryFlags $searchSpec.details.fileSize = $true $taskMoRef = $dsBrowser.SearchDatastoreSubFolders_Task($datastorePath, $searchSpec) $task = Get-View $taskMoRef while ($task.Info.State -eq "running"){$task = Get-View $taskMoRef} foreach ($result in $task.info.Result){ foreach($file in $result.File){ Write-Host $file.Path $file.FileSize } }