Reputation: 327
Can anyone help me with below code of PowerShell :
Please let me know if this is not the right platform for this question.
I am trying to get the unused space by subtracting total and free space and facing below error.
Also can I get help on how to get the free space percentage.
$srv=$env:COMPUTERNAME
$frspace=Get-WmiObject win32_volume -ComputerName $srv | Select @{N='FreeSpace';e={[Int]($_.FreeSpace/1GB)}}
$totSpace=Get-WmiObject win32_volume -ComputerName $srv | Select @{N='capacity';e={[Int]($_.capacity/1GB)}}
$unused=$totSpace-$frspace
Upvotes: 0
Views: 481
Reputation: 1972
How's this?
$srv=$env:COMPUTERNAME
Get-WmiObject win32_volume -ComputerName $srv | select Name, @{N='FreeSpace';e={[Int]($_.FreeSpace/1GB)}}, @{N='capacity';e={[Int]($_.capacity/1GB)}}, @{n="FreeSpace%"; e={"{0:N2}" -f (100*$_.FreeSpace / $_.capacity)}}
Upvotes: 1