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
Try something like this
$report = @() foreach($cluster in Get-Cluster){ 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-Csv "C:\cluster-ds.csv" -NoTypeInformation -UseCulture
If you want to have a cluster per worksheet in a spreadsheet, you could use the function from my post called Beyond Export-Csv: Export-Xls
The script would change slightly.
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"
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try something like this
$report = @() foreach($cluster in Get-Cluster){ 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-Csv "C:\cluster-ds.csv" -NoTypeInformation -UseCulture
If you want to have a cluster per worksheet in a spreadsheet, you could use the function from my post called Beyond Export-Csv: Export-Xls
The script would change slightly.
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"
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you soo much! Both work flawlessly.
I do have a few more questions, but the reports were needed and I can now provide them. The other items I'm going to try to figure out on my own...hopefully I can better undertand things this way :smileylaugh:.
Anyways, thanks again....not only for this response, but for all the information that you've given me indirectly.
Hi Luc,
I am using this script together with your xls function and it works great.
Is it possible since I am using vsphere 5 with clustered datastores to get the total amount of presented storage in the cluster, total amount of provisioned storage, total amount of used storage per TAB.
Do a formula of presented storage in the cluster minus total amount of provisioned storage. I wanna use this to do storage planning since I am using thin provisioning.
Thanks,
Alberto-
A datastorecluster is created on the datacenter level.
Are your DSC dedicated to specific clusters, or can a DSC be used from multiple cluster in your environment ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Each DSC is used by one cluster. Not shared by multiple clusters.
thanks,
Alberto
I meant in my environment.
I added FreeSpaceMB. With deduped data, 'available' can show negative values and doesn't always give a good picture to what is really free.
$report = @()
foreach($cluster in Get-Cluster){
Get-VMHost -Location $cluster | Get-Datastore | %{
$info = "" | select DataCenter, Cluster, Name, Capacity, FreeSpaceMB, Provisioned, Available
$info.Datacenter = $_.Datacenter
$info.Cluster = $cluster.Name
$info.Name = $_.Name
$info.Capacity = [math]::Round($_.capacityMB/1024,2)
$info.FreeSpaceMB = $_.ExtensionData.Summary.FreeSpace/1GB
$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
}
}
Hi
How do we add VMs on the Datastore to this report?
Cheers
Try something like this
$report = @()
foreach($cluster in Get-Cluster){
foreach($esx in Get-VMHost -Location $cluster){
foreach($vm in Get-VM -Location $esx){
Get-Datastore -RelatedObject $vm | %{
$info = "" | select DataCenter, Cluster, VM, Datastore, Capacity, FreeSpaceMB, Provisioned, Available
$info.Datacenter = $_.Datacenter
$info.Cluster = $cluster.Name
$info.VM = $vm.Name
$info.Datastore = $_.Name
$info.Capacity = [math]::Round($_.capacityMB/1024,2)
$info.FreeSpaceMB = $_.ExtensionData.Summary.FreeSpace/1GB
$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
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Champion thank you.
hi all i'm looking for a script that i can run against a virtual center to see all changes there were made in the last 24 hours on all luns and vms and who made them. new vm's, added memory, or anything that would take up space on a lun that would be a manual change.
thank you in advance!
Hi Lucd,
could you please provide me the script in getting datastore report in below format
Name | Capacity GB | Provisioned GB | Capacity in %(provisined/capacity) | In Use GB | Free GB | Free % |
datastore1 | 129 | 0.94921875 | 0.74 | 0.94921875 | 128 | 99 |
Hi LucD,
If possible with that script :
$report = @() foreach($cluster in Get-Cluster){ 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-Csv "C:\cluster-ds.csv" -NoTypeInformation -UseCulture
Get a report for 2 cluster? or in case that is not possible, get a report for an specfic cluster e.g Cluster-test .
I test the script and work fine but if a have 2 cluster the script take either cluster-test or cluster-test1.
Best regards
You can specify one or more clusternames on the Get-CLuster cmdlet.
The outer loop could be
foreach($cluster in Get-Cluster -Name cluster-test,cluster-test1)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
I modify the script with twoo clusters :
foreach($cluster in Get-Cluster -Name HCS-Service,HCS-mgmt){
And i got only a report from HCS-Service.
DataCenter | Cluster | Name | Capacity | Provisioned | Available |
TA | HCS-service | DS_AHTA2PRHCSSVR0301_local | 2,5 | 0,58 | 1,92 |
TA | HCS-service | EMC_HCS_1000 | 1023,75 | 591,03 | 432,72 |
TA | HCS-service | EMC_HCS_1001 | 1023,75 | 660,96 | 362,79 |
TA | HCS-service | EMC_HCS_1004 | 1023,75 | 796,26 | 227,49 |
TA | HCS-service | EMC_HCS_1005 | 1023,75 | 832,25 | 191,5 |
TA | HCS-service | EMC_HCS_1006 | 1023,75 | 751,76 | 271,99 |
TA | HCS-service | EMC_HCS_1007 | 1023,75 | 741,85 | 281,9 |
TA | HCS-service | EMC_HCS_1008 | 1023,75 | 862,09 | 161,66 |
😞
Best regards
If you do just Get-Cluster -Name HCS-Service,HCS-mgmt, it does return two cluster objects ?
You could also try to place the expression (Get-Cluster -Name HCS-Service,HCS-mgmt) between parenthesis.
Otherwise attach the script you are using, there might be something else that goes wrong.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
With :
PowerCLI C:\PS-Scripts> Get-Cluster -Name HCS-service-mgmt the prompt return twoo cluster.
Name HAEnabled HAFailover DrsEnabled DrsAutomationLe
Level vel
---- --------- ---------- ---------- ---------------
HCS-service True 0 False FullyAutomated
HCS-mgmt True 0 False FullyAutomated
PowerCLI C:\PS-Scripts>
But if a put the the expression (Get-Cluster -Name HCS-Service,HCS-mgmt) between parenthesis im only see stats from HCS-X1
best regards
Below the script.
add-PSSnapin VMware.VimAutomation.Core
Connect-VIServer x.x.x.x -Force -User domain\user -Password pass
$fecha = get-date -Format D
foreach($cluster in Get-Cluster -Name HCS-service,HCS-mgmt){
$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-Csv c:\ReportesvCENTER\ds-cluster$(Get-Date -f yyyyMMdd-hhmm)-$fecha.csv -NoTypeInformation -UseCulture }
That is because you initialise the array $report inside the Foreach loop.
Move the line $report = @() outside the foreach loop.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference