Wednesday, February 24, 2021

Drive space via powershell

If you want to get info for a remote server, you need to call the following.  This will enter a remote powershell session on the remote host.

 Enter-PSSession <hostname>

The following command will return the used and free space for the C: and Z: drives.

get-psdrive <drive> | ? {$_.Name -eq "Z" -or $_.Name -eq "C"} |  % {"Free(GB) " + $_.Free/1GB + " Used(GB) " + $_.Used/1GB]




As you see this command calls get-psdrive which gets the info for all drives.  You can optionally pass in which drive you want to get info for.  In this case it returns all drives so we can then select the two drives we are interested in.  The last step formats the output for each object in the pipeline.






No comments:

Post a Comment