≡ Menu

Check disk space of remote machine using PowerShell

[PLEASE USE http://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
}

 

{ 6 comments… add one }
  • srini April 19, 2011, 10:54 pm

    Above Script is not working at all, if you make it user friendly then it will be fine, i m getting error while running this script in PS gui editor.

    I dont know whre it is going to save the O/P file ??????

  • Sitaram Pamarthi April 19, 2011, 11:15 pm

    Srini, What is the error you are getting? Note that above code will not save the output to file but it will display the output to powershell console.

  • Sitaram Pamarthi April 19, 2011, 11:37 pm

    I felt the Syntax highlighter is causing some formatting issues. I removed it now

  • Fat Boy Tim September 21, 2011, 3:40 pm

    OR:

    $servername = XXX
    Invoke-Command -ComputerName $servername -ScriptBlock { Get-PSDrive -PSProvider “FileSystem” }

  • Sitaram Pamarthi September 21, 2011, 4:10 pm

    Tim, that works only if you have other system enabled for powershell remoting. To make it consistent across platforms, I prefer WMI methods.

Leave a Comment