VMDK's seem to have both a provisioned-size and real-size, but I'm unable to find that. How can i both the used and provisioned size of a file on a datastore? Does the Dsbrowser method have some other criteria for returning the provisioned- and reai-size similar to the HostDatastoreBrowserSearchSpec?
get-view -viewtype Datastore | % {
$ds = $psitem
$this_ds_vcenter = $ds.client.VimService.Via.host
#get dsbrowser
$dsBrowser = Get-View $ds.Browser -Server $this_ds_vcenter
$rootPath = "[" + $ds.Name + "]"
$fileQueryFlags = [VMware.Vim.FileQueryFlags]::new()
$fileQueryFlags.FileOwner = $true
$fileQueryFlags.FileSize = $true
$fileQueryFlags.Filetype = $true
$fileQueryFlags.Modification = $true
$searchSpec = [VMware.Vim.HostDatastoreBrowserSearchSpec]::new()
$searchSpec.details = $fileQueryFlags
# $searchSpec.matchPattern = $filesearchPattern
$searchSpec.sortFoldersFirst = $true
#files contains FileSize per FileQueryFlags, but does not provide actual size for thin vmdk 's
$files = $dsBrowser.SearchDatastoreSubFolders( $rootPath , $searchSpec )
}
Have a look at my yadr – A vdisk reporter post.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Mr LucD, do you ever rest?
I see in your code that you're determining thin vs thick by viewing the
virtualmachine.Config.Hardware.Device.DeviceInfo.Label.Backing.ThinProvisioned
Do you know if a property exists on the VMware.Vim.Datastore object for determining thin vs thick? I ask because I'm trying to determine the size of orphaned files. Since the vm on the datastore is not registered, no VMware.Vim.VirtualMachine exists in vcenter for those files.
You can use the SearchDatastoreSubFolders method to find all VMDK on a Datastore.
That will show all VMDK on that Datastore, also the orphaned ones.
And it will show if a VMDK is Thin or not.
$dsName = 'MyDatastore'
$ds = Get-Datastore -Name $dsName
$browser = Get-View -Id $ds.ExtensionData.Browser
$flags = New-Object VMware.Vim.FileQueryFlags
$flags.FileOwner = $true
$flags.FileSize = $true
$flags.FileType = $true
$flags.Modification = $true
$qDisk = New-Object VMware.Vim.VmDiskFileQuery
$qDisk.Details = New-Object VMware.Vim.VmDiskFileQueryFlags
$qDisk.Details.CapacityKB = $true
$qDisk.Details.DiskExtents = $true
$qDisk.Details.DiskType = $true
$qDisk.Details.HardwareVersion = $true
$qDisk.Details.Thin = $true
$searchSpec = New-Object VMware.Vim.HostDatastoreBrowserSearchSpec
$searchSpec.details = $flags
$searchSpec.Query = @($qDisk)
$searchSpec.sortFoldersFirst = $true
$rootPath = "[" + $ds.Name + "]"
$browser.SearchDatastoreSubFolders($rootPath, $searchSpec) |
ForEach-Object -Process {
$folder = $_
$_.File | ForEach-Object -Process {
New-Object -TypeName PSObject -Property ([ordered]@{
Datastore = $ds.Name
Folder = $folder.FolderPath
Name = $_.Path
Thin = $_.Thin
FileSizeKB = [math]::Round($_.FileSize/1KB,0)
CapacityKB = $_.CapacityKb
})
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference