Get SharePoint 2013 Server Disk Space using PowerShell

This PowerShell SharePoint 2013 tutorial explains how to get SharePoint 2013 server disk space using PowerShell in SharePoint 2013/2016.

Scenario / Issue:
It is always a challenging task to validate the disk space on a server using RDP (Remote Desktop Protocol) when you have a larger FARM or Network configured in your organization. Through you are ready to do RDP on all the servers it will be really hectic to sum-up all the used space and free space on every drive.

In this article, I would like to introduce a quick want to avoid this legacy and manual way of validating disk space on servers. PowerShell has extremely powerful objects/methods and techniques to break this hard edge.

PowerShell Script to retrieve SharePoint 2013 server disk space

I have created a PowerShell script that will be really handy to administrators to validate the disk space on every server from his/her local machine. You can run Visual Studio Code to write, run, debug, and test PowerShell script.

Below is the PowerShell script:

function Get-RemoteComputerDisk ($RemoteCompterName) {
Begin {
$output = “Dive `t UsedSpace (in GB) `t freeSpace (in GB) `t totalSpace (in GB) `n”
}
Process {
$drivers = Get-WmiObject Win32_LogicalDisk -ComputerName $RemoteCompterName
Write-Host “Server Name=” $RemoteCompterName
$totalDiskSpace = 0
foreach ($drive in $drivers) {
$driverName = $drive.DeviceID
$freespace = [int] ($drive.freeSpace / 1GB)
$totalspace = [int] ($drive.Size / 1GB)
$usedspace = $totalspace – $freespace
$output = $output + $driverName + “`t`t” + $usedspace + “`t`t`t” + $freespace + “`t`t`t” + $totalspace + “`n”
$totalDiskSpace = $totalDiskSpace + $totalspace
}
Write-Host “Total Disk Space= “$totalDiskSpace
}
End {
return $output
}
}
$srvName = Read-Host “Please enter the Server Name”
Get-RemoteComputerDisk -RemoteCompterName $srvName

This will provide the below output:

Get Server Disk Space using powershell
Get Server Disk Space using powershell

You may like following SharePoint PowerShell tutorials:

Hope this PowerShell SharePoint 2013 tutorial explains how to get SharePoint 2013 server disk space using PowerShell.

>