Hi All,
I am looking for a script which can fetch datastore usage in percentage. i have one script and i am getting the report as below in percentage free space, instead i need the data in percentage with total usage in percentage.
DataStoreName | Percentage Free Space(%) |
datastore1 | 92.07 |
datastore2 | 71.59 |
datastore3 | 71.6 |
datastore4 | 75.19 |
thanks in advance
Try like this
Select Name,
@{N='Used Space(%)';E={[math]::Round((($_.CapacityGB - $_.FreeSpaceGB)/$_.CapacityGB*100),1)}}
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try like this
Select Name,
@{N='Used Space(%)';E={[math]::Round((($_.CapacityGB - $_.FreeSpaceGB)/$_.CapacityGB*100),1)}}
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you very mush LucD,
One more thing, can we add below script with the percentage usage :
get-datastore | select-object name,@{Label=”FreespaceGB”;E={“{0:n2}” -f ($_.FreespaceGB)}}, CapacityGB, @{Label=”Provisioned”;E={“{0:n2}” -f ($_.CapacityGB – $_.FreespaceGB +($_.extensiondata.summary.uncommitted/1GB))}}|sort name | export-csv datastores.csv
So that i could get the below output:
Name | FreespaceGB | CapacityGB | Provisioned | Used Space % |
thanks
prateek
Sure, but that is just adding properties on the same Select-Object.
Like this
Select Name,
@{N=”FreespaceGB”;E={“{0:n2}” -f ($_.FreespaceGB)}},
CapacityGB,
@{N=”Provisioned”;E={“{0:n2}” -f ($_.CapacityGB – $_.FreespaceGB +($_.extensiondata.summary.uncommitted/1GB))}},
@{N='Used Space(%)';E={[math]::Round((($_.CapacityGB - $_.FreeSpaceGB)/$_.CapacityGB*100),1)}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
I tried below script but it throws an error
PS D:\vmk> .\Datastore.ps1
At D:\vmk\Datastore-freespace.ps1:1 char:5
+ $Get-Datastore |
+ ~~~~~~~~~~
Unexpected token '-Datastore' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : UnexpectedToken
thanks
vmk
That dollar-sign ($) in front of Get-Datastore shouldn't be there
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
Sorry for late reply. i'll check and will let you know. But if want to know the specific data store utilization example _VMAX_WIN and Oracle_VMAX_ then how to get the report for utilization and % percentage free. Kindly help me
thanks
v
You can use the Name parameter on the Get-Datastore cmdlet.
Get-Datastore -Name $dsNames |
Select Name,
@{N=”FreespaceGB”;E={“{0:n2}” -f ($_.FreespaceGB)}},
CapacityGB,
@{N=”Provisioned”;E={“{0:n2}” -f ($_.CapacityGB – $_.FreespaceGB +($_.extensiondata.summary.uncommitted/1GB))}},
@{N='Used Space(%)';E={[math]::Round((($_.CapacityGB - $_.FreeSpaceGB)/$_.CapacityGB*100),1)}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
it's working fine. is it possible to add % free space along with data used % (already added) ?
thanks
v
Try like this
Get-Datastore -Name $dsNames |
Select Name,
@{N=”FreespaceGB”;E={“{0:n2}” -f ($_.FreespaceGB)}},
CapacityGB,
@{N=”Provisioned”;E={“{0:n2}” -f ($_.CapacityGB – $_.FreespaceGB +($_.extensiondata.summary.uncommitted/1GB))}},
@{N='Used Space(%)';E={[math]::Round((($_.CapacityGB - $_.FreeSpaceGB)/$_.CapacityGB*100),1)}},
@{N='Free Space(%)';E={[math]::Round(($_.FreeSpaceGB/$_.CapacityGB*100),1)}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
When i tried to export into csv format but it throws an error. Any idea why ?
Get-Datastore |
Select Name,
@{N=”FreespaceGB”;E={“{0:n2}” -f ($_.FreespaceGB)}},
CapacityGB,
@{N=”Provisioned”;E={“{0:n2}” -f ($_.CapacityGB – $_.FreespaceGB +($_.extensiondata.summary.uncommitted/1GB))}},
@{N='Used Space(%)';E={[math]::Round((($_.CapacityGB - $_.FreeSpaceGB)/$_.CapacityGB*100),1)}}
$report | Export-Csv -path c:\Temp\dsreport-Marc19.csv
Thanks
V
I'm not sure why you are using the $report variable, but try like this
Select-Object Name,
@{N = ”FreespaceGB”; E = { “{0:n2}” -f ($_.FreespaceGB) } },
CapacityGB,
@{N = ”Provisioned”; E = { “{0:n2}” -f ($_.CapacityGB – $_.FreespaceGB + ($_.extensiondata.summary.uncommitted / 1GB)) } },
@{N = 'Used Space(%)'; E = { [math]::Round((($_.CapacityGB - $_.FreeSpaceGB) / $_.CapacityGB * 100), 1) } } |
Export-Csv -path c:\Temp\dsreport-Marc19.csv
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank LucD. It worked for me