PowerCLI: SAN Usage Report

PowerCLI: SAN Usage Report

 

Okay, today I have been tasked to find out where all of our storage has gone and because this SAN LUN is shared between a multiple of systems I have decided to generate the report based on Folder size within the LUN. Please see below for the script to run from PowerCLI

$searchSpec1 = New-Object VMware.Vim.HostDatastoreBrowserSearchSpec
$searchSpec1.details = New-Object VMware.Vim.FileQueryFlags
$searchSpec1.details.fileSize = $true
$searchSpec1.query += New-Object VMware.Vim.FolderFileQuery
$searchSpec2 = New-Object VMware.Vim.HostDatastoreBrowserSearchSpec
$searchSpec2.details = New-Object VMware.Vim.FileQueryFlags
$searchSpec2.details.fileSize = $true
$searchSpec2.query += New-Object VMware.Vim.FileQuery
$report = @()
Get-Datastore | Get-View | % {
$browser = Get-View -Id ($_.Browser)
$dsPath = "[" + $_.Summary.Name + "] /"
$folderList = $browser.SearchDatastore($dsPath, $searchSpec1)foreach($folder in $folderList.File){
$folderPath = $dsPath + $folder.Path
$fldresult = $browser.SearchDatastore($folderPath, $searchSpec2)
$fldSize = 0
foreach($file in $fldresult.File){$fldSize += $file.FileSize}
$row = "" | select DSName, FolderName, FolderSize
$row.DSName = $folderList.FolderPath
$row.FolderName = $folder.Path
$row.FolderSize = $fldSize
$report += $row
}
}
$report | Export-Csv "c:\powershell\Foldersize.csv" -noTypeInformation

Once you have harvested your CSV import it into excel and use the following on the custom format for file size

[<500000]#,##0" B ";[<500000000]#,##0,," MB";#,##0,,," GB"
Advertisements