Get SharePoint 2013 Server Disk Space using PowerShell

Get Server Disk Space using powershell

Scenario / Issue:
It is always a challenging task to validate the disk space on 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 an extremely powerful objects / methods and techniques to break this hard edge.

Solution:
I have created a PowerShell script which 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.



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

Hope this helps !!!!

Similar SharePoint 2013 Tutorials


Leave a Reply