Home > PowerShell > Powershell function to Check disk free space on remote computers

Powershell function to Check disk free space on remote computers

[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.]

Description:

This function takes the computer name as argument and displays the disk free/total size information. One advantage with this function is, no need to search for admin windows when you want to run it. It prompts for admin credentials and connects to remote computer using them.

Usage:

PS C:temp> Check-Diskspace -computer remotepc
cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
Credential
Drive Name :  C:

Total Space :  232.83 GB

Free Space :  0.94 GB

PS C:temp>

Code:

[powershell]
function Check-Diskspace {

param (

[parameter(Mandatory = $true)]

[string]$computer

)

$cred = Get-Credential

$drives = gwmi <em>-class</em> Win32_LogicalDisk <em>-computer</em> $computer <em>-credential</em> $cred | where { $_.DriveType -eq 3 }

foreach ($drive in $drives) {

write-host "Drive Name : " $drive.DeviceID

write-host "Total Space : "($drive.size/1GB).ToString("0.00") "GB"

write-host "Free Space : " ($drive.FreeSpace/1GB).ToString("0.00") "GB"

write-host " "

}

$cred = $null

}
[/powershell]

  1. No comments yet.
  1. No trackbacks yet.

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>