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:
You may like following SharePoint PowerShell tutorials:
- Bulk SharePoint Online Site Collection Creation using PowerShell
- Update User Email-ID using PowerShell in SharePoint 2013
- Delete Hidden Web Application in SharePoint 2013 using PowerShell
- Upload documents from network drive to SharePoint 2013 or SharePoint 2016 Server docuemnt library using PowerShell
- Working with PowerShell Variables
- SharePoint 2013 backup and restore using PowerShell
- How to create and use PowerShell global variable
Hope this PowerShell SharePoint 2013 tutorial explains how to get SharePoint 2013 server disk space using PowerShell.
I am Krishna.Vandanapu a SharePoint architect working in IT from last 13+ years, I worked in SharePoint 2007, 2010, 2013, 2016 and Office 365. I have extensive hands on experience in customizing SharePoint sites from end to end. Expertise in SharePoint migration tools like Sharegate, Doc Ave and Metalogix. Migrated SharePoint sites from SharePoint 2007 to 2010 and 2010 to 2013 several times seamlessly. Implementing CSOM with Microsoft best practices. Spent quality time in configuring SharePoint application services like User Profile, Search, Managed Meta data services etc. Now exploring SharePoint Framework and SharePoint 2019