Quantcast
Channel: Greg's Blog
Viewing all articles
Browse latest Browse all 20

Powershell function to get remote disk space

$
0
0

I was working on a project and needed to remotely check a servers available disk space so I started trying to come up with a simple reusable function to check the disk space.  The following is what I came up with. 

Function GetDiskSpace

{
<#
.SYNOPSIS
GetDiskSpace displays the Total Size and Total Free Space of a Remote Computer Drive
.DESCRIPTION
See synopsis
.EXAMPLE
To run – enter GetDiskSpace
#>
$computer = Read-host "Please enter the computer name"
$drive = Read-host "Please enter the drive letter including the colon (c:)"
$disk = Get-WmiObject Win32_LogicalDisk -ComputerName $computer -Filter "DeviceID=’$drive’" | Select-Object Size,FreeSpace
"Remote computer: $computer drive letter $drive has {0:#.0} GB free of {1:#.0} GB Total" -f ($disk.FreeSpace/1GB),($disk.Size/1GB) | write-output

}
Set-alias GDS GetDiskSpace


Filed under: PowerShell Tagged: functions, Powershell, remote

Viewing all articles
Browse latest Browse all 20

Trending Articles