1

I am using the following command to check space on remote server:

Get-WmiObject -Class win32_logicalDisk -ComputerName computer-name | Select Name,@{n="Free";e={[math]::trun
cate($_.freespace / 1GB)}}, @{n="Total Size";e={[math]::truncate($_.size / 1GB)}}

It outputs:

Name Free Total Size
---- ---- ----------
C:     13         59
D:      0          0

However, the actual space is: 10.5 free from 59.8. It's like it's using int, not float. Anyone know how can I change it in order to show the real float values?

1

Found it. It seems I need to use abs instead of the truncate function.

Get-WmiObject -Class win32_logicalDisk -ComputerName computer-name | Select Name,@{n="Free";e={[math]::abs(
$_.freespace / 1GB)}}, @{n="Total Size";e={[math]::abs($_.size / 1GB)}}
0

or Get-WmiObject -Class win32_logicalDisk -ComputerName computer-name | Select Name,@{n="Free";e={[($.freespace / 1GB) -as [int]}}, @{n="Total Size";e={$.size / 1GB -as [int])}}

2
  • Welcome to Super User! Please take the tour and read through the help center center. Here is a guide on How to Ask and How to Answer. Please note the conventions for formatting How do I format my posts using Markdown or HTML. Code-only answers are considered low quality: make sure to provide an explanation what your code does and how it solves the problem. – help-info.de Feb 9 at 12:55
  • Before answering an old question having an accepted answer (look for green ✓) as well as other answers ensure your answer adds something really new or is otherwise helpful in relation to them. – help-info.de Feb 9 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.