[PLEASE USE https://techibee.com/powershell/check-disk-space-of-remote-machine-using-powershell/430 to check free disk space of remote computer. I made it more advanced there.]
Earlier I have written a onliner to find out the disk space of remote machine. Few of my friends told me that it’s format is not good and can be improved. With the skills I have acquired these days in powershell, I made another attempt to re-write it, and this time it’s a function with some neat formatting.
Another improvement in this post is, here I am using SyntaxHighliter to give a nice view of my powershell code. Thanks to the author of this WP plug-in. This plug-in sucks. It is changing the format of my powershell code.
function Check-Diskspace { param ( [parameter(Mandatory = $true)] [string]$computer ) $cred = Get-Credential $DriveName1 = @{name=”DriveName”;Expression={$_.DeviceID+””}} $TotalSpace = @{name=”Total Space”;expression = {($_.size/1GB).ToString(“0.00")+” GB"}} $FreeSpace = @{name=”Free Space”;expression = {($_.FreeSpace/1GB).ToString(“0.00")+” GB”}} gwmi -Class Win32_logicalDisk -filter “Drivetype=’3'” -computer $computer -credential $cred | Select $DriveName1, $TotalSpace, $FreeSpace | ft -auto $cred = $null }