Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello All,
I am attempting to create a script which will add up the total available and used size of all volume
here is my script
$vols = Get-NcVol
$voltotal = $vols | Measure-Object -Property TotalSize -Sum
$voltotalsize = ConvertTo-FormattedNumber $voltotal.sum DataSize -Verbose
$volused = $vols | Measure-Object -Property Used -Sum
$volusedsize = ConvertTo-FormattedNumber $volused.sum DataSize -Verbose
It is giving me wrong numbers I think this is because the get-ncvol give volume size in Gb,Tb and Mb so we basically can not add apple to orange
Has anyone everdone that ? can you give me an exemple ?
Solved! See The Solution
1 ACCEPTED SOLUTION
sakalava has accepted the solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thanks a lot
I think I found an alternative
Get-NcVol | ForEach-Object {
$x = "" | Select Name,Total_TB,Available_TB
$x.Name = $_.Name
$x.Total_TB = [Math]::Round($_.TotalSize / 1TB, 2)
$x.Available_TB = [Math]::Round($_.Available / 1TB, 2)
$x | Format-Table -AutoSize | Out-String | ForEach-Object { $_.Trim("`r","`n") }
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Perhaps convert everything to bytes first then total and convert back to whichever unit you want?
function Convert-UnitsToBytes {
[cmdletbinding()]
param (
[Parameter(Mandatory = $True)]
[uint64]$Size,
[Parameter(Mandatory = $True)]
[ValidateSet('MB', 'GB', 'TB')]$Unit
)
# Converts BYTES to a specified UNIT (MB|GB|TB)
# - Any other Unit will return the original value passed in
$Unit = $Unit.ToUpper()
switch ($Unit) {
'MB' {
$bytes = $size * 1MB
}
'GB' {
$bytes = $size * 1GB
}
'TB' {
$bytes = $size * 1TB
}
Default {
$bytes = $size
}
}
return $bytes
}
sakalava has accepted the solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thanks a lot
I think I found an alternative
Get-NcVol | ForEach-Object {
$x = "" | Select Name,Total_TB,Available_TB
$x.Name = $_.Name
$x.Total_TB = [Math]::Round($_.TotalSize / 1TB, 2)
$x.Available_TB = [Math]::Round($_.Available / 1TB, 2)
$x | Format-Table -AutoSize | Out-String | ForEach-Object { $_.Trim("`r","`n") }
