Home > PowerShell > Check disk space of remote machine using PowerShell

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
}

 

Categories: PowerShell Tags:
  1. srini
    April 19, 2011 at 10:54 pm | #1

    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 ??????

  2. April 19, 2011 at 11:15 pm | #2

    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.

  3. April 19, 2011 at 11:37 pm | #3

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

  4. Fat Boy Tim
    September 21, 2011 at 3:40 pm | #4

    OR:

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

  5. Sitaram Pamarthi
    September 21, 2011 at 4:10 pm | #5

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

  1. September 8, 2010 at 2:21 pm | #1

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>