How to get disk capacity from remote server using Powershell Get-PSDrive

10 May,2021 by Jack Vamvas

Question: I capture drive space details for capacity planning  servers hosting SQL Server. The SQL Server policies on the organisations restrict the use of xp_cmdshell - which allows access to server information as an administrator. Increasing servers are locked down to decrease the surface area of attack. Are there methods using Powershell which support remote gathering of drive details?

 

Answer: Powershell does support gathering drive information on remote servers , using Get-PSDrive . But I want to offer at the same time a word of caution related to the very point you are making in your question.

You've mentioned organisations securing server assets further - particuarly in light of cyber attacks and some other high profile Ransomware attacks of recent years. In applying any remote gathering of server data consider the security consequences. 

Back to the question of whether Powershell supports remote access of remote server drive information . This is an example of how to Invoke a command - wrapping Get-PSDrive - and executing on a remote server. 

 

Invoke-Command -ComputerName myserver1 {Get-PSDrive | Where {$_.Free -gt 0}}

 

--the command above returns a resultset with these columns

Name | Used (GB)  |Free (GB)  | Provider | Root | CurrentLocation | PSComputerName

 

Read more on Powershell 

Expand your Powershell mind – Three key cmdlets (SQL Server DBA)

3 methods to get the drive sizes with Powershell


Author: Jack Vamvas (http://www.sqlserver-dba.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment on How to get disk capacity from remote server using Powershell Get-PSDrive


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer