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.
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.
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.
So the full command is:
Invoke-Command -Computername <Computer name> {Get-PSDrive | Where {$_.Free}}
In practice, it looks like this:
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.