Checking C drive space is really important for windows computers, this article explains to you how to Check C Drive Space on multiple remote computers, here is the simple code that one can use find the C drive space.
When you want to check the C drive system drive utilization on the local computer then one can simply open my computer and can find the drive space, however when are multiple remote computers then one has to use a PowerShell script, this article provides you a simple script that prints C drive utilization of remote computers on the screen.
There are two ways one can check the C drive information, using WMI and a cmdlet Get-PSDrive, let’s discuss both ways.
On a local computer using the WMI command.
get-WmiObject win32_logicaldisk
Output
On a local computer using the Get-PSDrive command.
Get-PSDrive
C Drive Space Check on Remote Computers
We need to create a text file for storing all the servers or multiple machines lists, I named it as Allserver.txt for and saved it in my local machine c:\temp\Allserver.txt
$allservers =get-content -path "c:\temp\Allservers.txt" foreach ($oneserver in $allservers) { $disk = Get-WmiObject Win32_LogicalDisk -ComputerName $oneserver -Filter "DeviceID='C:'" | Select-Object Size,FreeSpace } $disk.Size $disk.FreeSpace
C Drive Space Check on Remote Computers using Get-PSDrive.
$allservers =get-content -path "c:\temp\Allservers.txt" foreach ($oneserver in $allservers) { $diskinfo = invoke-command -computername $oneserver -scriptblock { Get-PSDrive C | Select-Object @{ E={$_.Used/1GB}; L='Used' }, @{ E={$_.Free/1GB}; L='Free' }<br> } } $diskinfo.free $diskinfo.used
Both these two scripts work as expected, the output is the same, however when I use PSDrive then got a bit faster results than WMI.
Thank you for reading this article, if you have any questions please let us know.
Thank you for visiting my site, for any scripts in these articles you are testing please make sure you have tested this script in our lower environment before you run in production.
Leave a Reply Cancel reply