locked
How to get space disk rounded with math function RRS feed

  • Question

  • Hi, could you please explain how i can get the result rounded with 2 decimals ? 

        $PartitionActualSize = $Partition.Size;
    
        $PartitionActualSize = [math]::round($Partition[$_] /1Gb, 2)
    

    Tuesday, September 11, 2018 3:54 PM

All replies

  • $_ is the current object on the pipeline which I do not see you using

    Maybe this as you have incomplete code?

    $PartitionActualSize = $Partition.Size;
    $PartitionActualSize = [math]::round($PartitionActualSize /1Gb, 2)


    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''

    Tuesday, September 11, 2018 3:59 PM
  • Why two lines?

    $PartitionActualSize = [math]::round($Partition.Size /1Gb, 2)

    Creating interim variables is unnecessary and is bad programming in any language.


    \_(ツ)_/

    • Proposed as answer by BOfH-666 Tuesday, September 11, 2018 5:49 PM
    Tuesday, September 11, 2018 4:49 PM
  • Why two lines?

    $PartitionActualSize = [math]::round($Partition.Size /1Gb, 2)

    Creating interim variables is unnecessary and is bad programming in any language.


    \_(ツ)_/

    I was just going off of the OP's script, but you are correct as usual :-)

    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''

    Tuesday, September 11, 2018 5:01 PM
  • Hi,

    Many thanks ! your right it works now !  

    I have a for each loop in my script for processing some stuff related to disk and partition management.

    $disks = Get-Disk | Where FriendlyName -ne "Msft Virtual Disk";

    foreach ($disk in $disks) { $DiskNumber = $disk.Number; Write-Host "Current processed DiskNumber is [$DiskNumber]" $Partition = Get-Partition -DiskNumber $disk.Number; Write-Host "Current Partition on DiskNumber [$DiskNumber] info is $Partition" #$PartitionActualSize = $Partition.Size; $PartitionActualSize = ([Math]::Round($Partition.Size/1GB,2)) Write-Host "Current Partition size is [$PartitionActualSize]GB" $DriveLetter = $Partition.DriveLetter; Write-Host "Current Partition Drive Letter is [${DriveLetter}:\]" $PartitionNumber = $Partition.PartitionNumber Write-Host "Current patrition Number is [$PartitionNumber]" $PartitionSupportedSize = Get-PartitionSupportedSize -DiskNumber $DiskNumber -PartitionNumber $PartitionNumber; $MaxPartitionSupportedSize = ([Math]::Round($PartitionSupportedSize.SizeMax/1GB,2)) Write-Host "Current Max Partition supported size is [$MaxPartitionSupportedSize]GB" }


    Tuesday, September 11, 2018 6:37 PM