0

I found a script to check the available space on a remote computer. However I can't find how I can get the output in GB instead of B. I don't know a lot about Powershell. Can somebody help me adjusting this code so I can see the available free disk space on a remote computer

$disk = Get-WmiObject Win32_LogicalDisk -ComputerName STR3598C -Filter "DeviceID='C:'" | Select-Object Size,FreeSpace 

$disk.Size
$disk.FreeSpace
Theo
  • 57,719
  • 8
  • 24
  • 41
  • If you actually looking for a more human readable format, see: https://stackoverflow.com/q/57530347/1701026 – iRon Sep 06 '19 at 15:37

2 Answers2

4

A possible way to achieve this could be to use the following:

gwmi win32_logicaldisk -ComputerName STR3598C -Filter "DeviceID='C:'" | Format-Table DeviceId, MediaType, @{n="Size";e={[math]::Round($_.Size/1GB,2)}},@{n="FreeSpace";e={[math]::Round($_.FreeSpace/1GB,2)}}

Expected output:

DeviceId MediaType   Size FreeSpace
-------- ---------   ---- ---------
C:              12 215.52     111.1
Matthew
  • 1,412
  • 2
  • 20
  • 35
1

Another way is to store the results in a variable (like with your code example) and format that for output to screen and/or save it in a CSV file:

$computer = 'STR3598C'
$disk = Get-WmiObject Win32_LogicalDisk -ComputerName $computer -Filter "DeviceID='C:'" | 
        Select-Object @{Name = 'Computer'; Expression = {$_.PSComputerName}},
                      DeviceID, VolumeName,
                      @{Name = 'Size'; Expression = {'{0:N2}' -f ($_.Size / 1GB)}},
                      @{Name = 'FreeSpace'; Expression = {'{0:N2} GB' -f ($_.FreeSpace / 1GB)}}

# output on screen
$disk | Format-Table -AutoSize

# or save the output as CVS
$disk | Export-Csv -Path 'D:\disksize.csv' -NoTypeInformation

Output on screen

Computer DeviceID VolumeName Size      FreeSpace
-------- -------- ---------- ----      ---------
STR3598C C:       Systeem    232,79 GB 89,33 GB
Theo
  • 57,719
  • 8
  • 24
  • 41