Hi All,
Im looking to create a Power CLI script that list all clusters into a Vcenter and theirs own datastores and storage baies details ( Name of the baie, Name of the datastore, Size of the datastore, Free space …). Could you please help me and let me know what can i add to this exemple ? i'm Open to any suggestion
$clusters = get-cluster
Foreach ($cluster in $clusters)
{
$cluster | get-datastore | % {
[pscustomobject] @{
'cluster' = $cluster.name
'datastore' = $_.name
}
}
}
Thanks
Please note that i did try this script and there was no output related to I/O any idea why ?
# Get a list of ESXi hosts
$esxiHosts = Get-VMHost
# Get a list of ESXi clusters
$esxiClusters = Get-Cluster
# Create an array to store the data
$data = @()
# Loop through each ESXi host and add the associated datastores, size, free space, storage array, and I/O details to the data array
foreach ($esxiHost in $esxiHosts) {
$esxiHostName = $esxiHost.Name
$datastores = Get-Datastore -VMHost $esxiHost
$esxiCluster = ($esxiHost | Get-Cluster).Name
foreach ($datastore in $datastores) {
$datastoreName = $datastore.Name
$datastoreSize = $datastore.CapacityGB
$freeSpace = $datastore.FreeSpaceGB
# Get I/O details for the datastore (adjust the time period as needed)
$ioStats = Get-Stat -Entity $datastore -Stat "datastore.numberReadAveraged.average", "datastore.numberWriteAveraged.average" -MaxSamples 1 -Realtime
$data += [PSCustomObject]@{
"ESXi Host" = $esxiHostName
"Datastore" = $datastoreName
"Cluster" = $esxiCluster
"Size (GB)" = $datastoreSize
"Free Space (GB)" = $freeSpace
"Reads per second" = $ioStats | Where-Object { $_.MetricId -eq "datastore.numberReadAveraged.average" } | Select-Object -ExpandProperty Value
"Writes per second" = $ioStats | Where-Object { $_.MetricId -eq "datastore.numberWriteAveraged.average" } | Select-Object -ExpandProperty Value
}
}
}
You could start by doing a search in this community, there are ample samples availables.
Those should give you some ideas on what to collect.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello,
Is there any possibility to add a line into the below script in order to show datastore I/O value in real time ?
$esxiHosts = Get-VMHost
$esxiClusters = Get-Cluster
$data = @()
foreach ($esxiHost in $esxiHosts) {
$esxiHostName = $esxiHost.Name
$datastores = Get-Datastore -VMHost $esxiHost
$esxiCluster = ($esxiHost | Get-Cluster).Name
foreach ($datastore in $datastores) {
$data += [PSCustomObject]@{
"ESXi Host" = $esxiHostName
"Datastore" = $datastore.Name
"Cluster" = $esxiCluster
"Size (GB)" = $datastore.CapacityGB
"Free Space (GB)" = $datastore.FreeSpaceGB
"Storage Array" = $datastore.ExtensionData.Info.Url
}
}
}
$data | Format-Table -AutoSize
Thanks
Hamdi
Please note that i did try this script and there was no output related to I/O any idea why ?
# Get a list of ESXi hosts
$esxiHosts = Get-VMHost
# Get a list of ESXi clusters
$esxiClusters = Get-Cluster
# Create an array to store the data
$data = @()
# Loop through each ESXi host and add the associated datastores, size, free space, storage array, and I/O details to the data array
foreach ($esxiHost in $esxiHosts) {
$esxiHostName = $esxiHost.Name
$datastores = Get-Datastore -VMHost $esxiHost
$esxiCluster = ($esxiHost | Get-Cluster).Name
foreach ($datastore in $datastores) {
$datastoreName = $datastore.Name
$datastoreSize = $datastore.CapacityGB
$freeSpace = $datastore.FreeSpaceGB
# Get I/O details for the datastore (adjust the time period as needed)
$ioStats = Get-Stat -Entity $datastore -Stat "datastore.numberReadAveraged.average", "datastore.numberWriteAveraged.average" -MaxSamples 1 -Realtime
$data += [PSCustomObject]@{
"ESXi Host" = $esxiHostName
"Datastore" = $datastoreName
"Cluster" = $esxiCluster
"Size (GB)" = $datastoreSize
"Free Space (GB)" = $freeSpace
"Reads per second" = $ioStats | Where-Object { $_.MetricId -eq "datastore.numberReadAveraged.average" } | Select-Object -ExpandProperty Value
"Writes per second" = $ioStats | Where-Object { $_.MetricId -eq "datastore.numberWriteAveraged.average" } | Select-Object -ExpandProperty Value
}
}
}
Afaik, these metrics only return Realtime values when the Entity is a VM.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference