How To View Disk Space with PowerShell

Windows PowerShell provides a simple and effective way to monitor the available disk space on your local computer and remote systems. This lets you stay informed about the free and occupied disk space, ensuring you have a clear view of your resources.

By utilizing PowerShell commands, you can easily retrieve information about the disk space and keep track of potential limitations or issues. This allows you to proactively manage your storage and ensure enough free space for your needs.

Advertisements

View free and used disk Space.

The cmdlet “Get-PSDrive‘ gives us information about all existing drives in a Windows PowerShell session. This includes local disks, connected network drives, and the PowerShell provider. By setting a filter, we only see drives that provide storage space as a file system.

Get-PSDrive | Where {$_.Free}

So this command will retrieve all internal drives – by selecting “Where {S_.Free}, “ but we limit the output to that Disk with free space.

Advertisements

free and used disk Space

Determine memory usage on remote PC

The whole thing naturally works remotely since we can also send commands to remote computers with PowerShell. You have to prefix it with the “Invoke command.” The only requirement: The PowerShell session must be run with a user with the appropriate permissions on the target system.

Advertisements
  How to Check Password Change History in PowerShell?

So the full command is:

Invoke-Command -Computername <Computer name> {Get-PSDrive | Where {$_.Free}}

In practice, it looks like this:

Advertisements

In this case, the remote Windows server only has one partition (C:), on which approx. 68 GB is left free disk space is available.

For example, this command can be integrated into a PowerShell script, which determines the memory usage of Windows servers in the network every hour. Theoretically, a warning could also be sent as an e-mail if the free space on a partition falls below a specific value.

Author
Follow:
Rohit is a certified Microsoft Windows expert with a passion for simplifying technology. With years of hands-on experience and a knack for problem-solving, He is dedicated to helping individuals and businesses make the most of their Windows systems. Whether it's troubleshooting, optimization, or sharing expert insights,