The following article will provide you script to check disk space. The Script monitor space on windows and multiple remote server. If you are tech guy, this solutions will save you some time and maybe some money.
Script to check disk space.
First will explain how to check disk space in windows from the command line. Second will explain the script to check disk space on multiple windows servers. This method will provide a csv file where will be listed all servers and information about the space. To realize those 2 methods we will need to use PStool.
To monitor disk space first you need to download PSTool suit from official Microsoft site:
Extract the zip file to desired folder for the example “D:\PStool_Example”. For the tasks below we need only PsInfo.exe and PsInfo64.exe.
How to check disk space in windows from the command line.
To check disk space in windows from command line please follow the below steps:
- Open cmd (Command line)
- Go to the folder where we extracted PSTool Suit – “cd D:\PStool_Example”
- Run “Psinfo -d \”
The command will display the info like the screen below:
Script to check disk space on multiple servers.
If you are trying to get disk space info from multiple servers you need to create script. The script will contain all commands to get the info from all servers specified on the source. After this will produce an excel output with all the info generated.
In the folder created previously create a new txt file named “free_space.cmd”. Copy the following commands and save.
REM ***START HERE***
IF EXIST Free_Disk_Space_Servers.csv DEL Free_Disk_Space_Servers.csv
FOR /F "Tokens=*" %%L IN (Hostlist.txt) DO (
Psinfo -d \ \\!ServerName!>> Free_Disk_Space_Servers.csv
REM ***END HERE***
Create another text file and save like “Hostlist.txt”. Open the text file and order all the IP servers that you need to get info:
The package is ready. Run the “free_space.cmd” file and the script with create a csv file where will write all the space info from the servers.
Note! Please be sure that your Account has Admin rights on the servers where you are trying to check hard drive space info.
This task can be scheduled on windows task scheduler. Check the following post for help.