Hello, I need report (last 12 months) with used space for DatastoreCluster and if some datastore is not in datastorecluster also for it
Table should like this:
Month PROD-cluster Used TB DEV-cluster Used TB LUN01 Used TB
Aug-17
Sep-17
okt 2017
Nov-17
Dec-17
Thank you very much
This version will report on all datastoreclusters and all datastores (that are not in a datastorecluster) over all connected vCenters.
$stat = 'disk.used.latest'
$start = (Get-Date).AddMonths(-12)
$stats = @()
$global:DefaultVIServers |
ForEach-Object -Process {
$vc = $_
$dsc = Get-DatastoreCluster -Server $vc
$dsinDSC = Get-Datastore -RelatedObject $dsc -Server $vc
$dsnotInDSC = Get-Datastore -Server $vc | where{$dsinDSC.Name -notcontains $_.Name}
Get-Stat -Entity $dsc -Stat $stat -Start $start -Server $vc
Get-Stat -Entity $dsnotInDSC -Stat $stat -Start $start -Server $vc
} | Group-Object -Property {$_.Timestamp.ToString('yyyyMM')} |
Sort-Object -Property @{E={$_.Name}} |
ForEach-Object -Process {
$obj = [ordered]@{
Month = "$((Get-Culture).DateTimeFormat.GetAbbreviatedMonthName($_.Name.SubString(4,2))) $($_.Name.SubString(0,4))"
}
$_.Group | Group-Object -Property {$_.Entity.Name} |
Sort-Object -Property Name |
ForEach-Object -Process {
$used = $_.Group | where{$_.MetricId -eq 'disk.used.latest'} |
Measure-Object -Property Value -Average |
Select -ExpandProperty Average
$obj.Add("$($_.Name) Used TB", [math]::Ceiling($used/1GB))
}
New-Object PSObject -Property $obj
} | Export-Csv -Path .\report.csv -UseCulture -NoTypeInformation
And no, it is possible but will require some extra logic.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try like this
$stat = 'disk.used.latest'
$start = (Get-Date).AddMonths(-12)
$dsc = Get-DatastoreCluster
Get-Stat -Entity $dsc -Stat $stat -Start $start |
Group-Object -Property {$_.Timestamp.ToString('yyyyMM')} |
Sort-Object -Property @{E={$_.Name}} |
ForEach-Object -Process {
$obj = [ordered]@{
Month = "$((Get-Culture).DateTimeFormat.GetAbbreviatedMonthName($_.Name.SubString(4,2))) $($_.Name.SubString(0,4))"
}
$_.Group | Group-Object -Property {$_.Entity.Name} |
Sort-Object -Property Name |
ForEach-Object -Process {
$used = $_.Group | where{$_.MetricId -eq 'disk.used.latest'} |
Measure-Object -Property Value -Average |
Select -ExpandProperty Average
$obj.Add("$($_.Name) Used TB", [math]::Ceiling($used/1GB))
}
New-Object PSObject -Property $obj
} | Export-Csv -Path .\report.csv -UseCulture -NoTypeInformation
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you, it is working but I found one issue - script didnt return usage history for all datastoreclusters, just for few. I changed $start = (Get-Date).AddMonths(-1) and then returned all datastoreclusters. Maybe it is caused that not all datastoreclusters have data for whole 12 months. Is it possible to correct this ?
And also could you add to report datastores which are not members of any datastorecluster please.
The Get-Stat cmdlet, and the underlying QueryPerf method, fail when there is no statistical data for the entity on the Start date.
In my Stats Toolbox – A VSphere Server Performance Counter Tool post I added the function Oldest to the script.
This option will find the oldest statistical data available for a specific entity.
Once you have that date, you can do the Get-Stat call with a Start date that will not fail the cmdlet.
The drawback is that you have to find that date and then you have to make individual calls for each entity, datastoreclusters in this case.
So it results in a lot more calls to Get-Stat.
Do you want datastorestoreclusters and datastores in the same worksheet?
That would make quite a cluttered impression.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Datastorestoreclusters and datastores should be in the same worksheet. But only datastores which are not members of datastorecluster. Is it possible to filter it ?
So it is not possible to find oldest statistical data available for a specific entity and then make individual get-stat call for each entity?
This version will report on all datastoreclusters and all datastores (that are not in a datastorecluster) over all connected vCenters.
$stat = 'disk.used.latest'
$start = (Get-Date).AddMonths(-12)
$stats = @()
$global:DefaultVIServers |
ForEach-Object -Process {
$vc = $_
$dsc = Get-DatastoreCluster -Server $vc
$dsinDSC = Get-Datastore -RelatedObject $dsc -Server $vc
$dsnotInDSC = Get-Datastore -Server $vc | where{$dsinDSC.Name -notcontains $_.Name}
Get-Stat -Entity $dsc -Stat $stat -Start $start -Server $vc
Get-Stat -Entity $dsnotInDSC -Stat $stat -Start $start -Server $vc
} | Group-Object -Property {$_.Timestamp.ToString('yyyyMM')} |
Sort-Object -Property @{E={$_.Name}} |
ForEach-Object -Process {
$obj = [ordered]@{
Month = "$((Get-Culture).DateTimeFormat.GetAbbreviatedMonthName($_.Name.SubString(4,2))) $($_.Name.SubString(0,4))"
}
$_.Group | Group-Object -Property {$_.Entity.Name} |
Sort-Object -Property Name |
ForEach-Object -Process {
$used = $_.Group | where{$_.MetricId -eq 'disk.used.latest'} |
Measure-Object -Property Value -Average |
Select -ExpandProperty Average
$obj.Add("$($_.Name) Used TB", [math]::Ceiling($used/1GB))
}
New-Object PSObject -Property $obj
} | Export-Csv -Path .\report.csv -UseCulture -NoTypeInformation
And no, it is possible but will require some extra logic.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference