Hello,
I was wondering if someone could help me with a script. I need to do an audit of our datastores with capacity, provisioned, and available. I did find a snippet of code which returns the information I need, but is there a way to indicate which cluster these DataStores are assigned to?
Here is the code I'm using.
$report
= @()
get-datastore
| % {
$info = "" | select DataCenter, Name, Capacity, Provisioned, Available
$info.Datacenter = $_.Datacenter
$info.Name = $_.Name
$info.Capacity = [math]::Round($_.capacityMB/1024,2)
$info.Provisioned = [math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB,2)
$info.Available = [math]::Round($info.Capacity - $info.Provisioned,2)
$report += $info
}
#$report | sort Available | format-table –auto
Ideally I'd like to have a spreadsheet with a seperate worksheet for each Cluster, but having a single sheet with all datastores and their cluster would be fine as well.
Thx
LucD,
Now is work !
Many thanks
Hi LucD,
I want to get even vmhost details in the given script. So please help on this.
Regards,
Babu Raju..
Could you be a bit more specific ?
Which of the scripts in this thread are you referring to ?
And how do you want the result to look ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
I am referring to the below script.
foreach($cluster in Get-Cluster){
$report = @()
Get-VMHost -Location $cluster | Get-Datastore | %{
$info = "" | select DataCenter, Cluster, Name, Capacity, Provisioned, Available
$info.Datacenter = $_.Datacenter
$info.Cluster = $cluster.Name
$info.Name = $_.Name
$info.Capacity = [math]::Round($_.capacityMB/1024,2)
$info.Provisioned = [math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB,2)
$info.Available = [math]::Round($info.Capacity - $info.Provisioned,2)
$report += $info
}
$report | Export-Xls -Path C:\ds-cluster.xls -WorksheetName $cluster.Name -SheetPosition "end"
}
here I want to have $info.Vmhost = " " details also
Regards,
Babu Raju...
cont.............
and in the result I want to have like this.
DataCenter | Cluster | VMHost IP | Name | Capacity | Provisioned | Available |
=========================================================
Regards
Babu Raju...
Try like this
$report = @()
foreach($cluster in Get-Cluster){
foreach($esx in Get-VMHost -Location $cluster){
Get-Datastore -RelatedObject $esx | %{
$info = "" | select DataCenter, Cluster, VMHost, Name, Capacity, Provisioned, Available
$info.Datacenter = $_.Datacenter
$info.Cluster = $cluster.Name
$info.VMHost = $esx.Name
$info.Name = $_.Name
$info.Capacity = [math]::Round($_.capacityMB/1024,2)
$info.Provisioned = [math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB,2)
$info.Available = [math]::Round($info.Capacity - $info.Provisioned,2)
$report += $info
}
}
}
$report | Export-Csv -Path C:\ds-cluster.xls
foreach($cluster in Get-Cluster){
$report = @()
foreach($esx in Get-VMHost -Location $cluster){
Get-Datastore -RelatedObject $esx | %{
$info = "" | select DataCenter, Cluster, VMHost, Name, Capacity, Provisioned, Available
$info.Datacenter = $_.Datacenter
$info.Cluster = $cluster.Name
$info.VMHost = $esx.Name
$info.Name = $_.Name
$info.Capacity = [math]::Round($_.capacityMB/1024,2)
$info.Provisioned = [math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB,2)
$info.Available = [math]::Round($info.Capacity - $info.Provisioned,2)
$report += $info
}
}
$report | Export-Xls -Path C:\ds-cluster.xls -WorksheetName $cluster.Name -SheetPosition "end"
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD,
It's worked for me now. Ur awesome..
Regards.
Babu Raju....