Part of our routine here is to run this pstools batch script to determine disk space. It's quite limited because you have to define evey server and drive explicitly, and it has problems when finding disk sizes under 100GB. So I decided to plunder and pillage a couple scripts and came up with something that mostly works.:
Issue #1. Disksize and Freespace, if it goes beyond 1TB, it adds another comma when it's writing and throws my colums off. I have been trying to find how to strip that comma but have not found a proper solution.
Issue #2. As you see by a commended line out, I would desire only to write to the file if it's reached below a threshold (in this case 15%) but every time I try to insert the line it's looking for a next condition, and every time I place one in it does not work.
Code:
Set iFSO = CreateObject("Scripting.FilesyStemObject")
Set oFSO = CreateObject("Scripting.FileSystemObject")
InputFile="computers.txt"
Outputfile="Diskspacelist.csv"
SET ofile = oFSO.CreateTextFile(OutputFile)
SET ifile = iFSO.openTextFile(inputfile)
Const GBCONVERSION= 1048576000
ofile.writeline "Server,Drive,Disk Size,FreeSpace,DiskPercent"
Do until ifile.AtEndOfLine
Server = ifile.ReadLine
SET objWMIService = GetObject("winmgmts://" & Server)
SET colLogicalDisk = objWMIService.InstancesOf("Win32_LogicalDisk")
FOR EACH objLogicalDisk In colLogicalDisk
Dim iThreshold
Dim DiskSpaceSize
Dim DiskPercent
IF objLogicalDisk.drivetype=3 then
Disksize = FormatNumber(objLogicalDisk.size/GBCONVERSION,2) & "GB"
DiskSpaceSize = objLogicalDisk.size
Freespace = FormatNumber(objLogicalDisk.freespace/GBCONVERSION,2) & "GB"
DiskPercent = FormatPercent (objLogicalDisk.freespace/objLogicalDisk.size)
DeviceID = objLogicalDisk.DeviceID
'If DiskPercent < 16 Then
ofile.writeline Server & "," & DeviceID & "," & Disksize & "," & Freespace & "," & DiskPercent
END IF
Next
SET colLogicalDisk = NOTHING
SET objWMIService = NOTHING
Loop
wscript.Echo "Check complete"
Issue #1. Disksize and Freespace, if it goes beyond 1TB, it adds another comma when it's writing and throws my colums off. I have been trying to find how to strip that comma but have not found a proper solution.
Issue #2. As you see by a commended line out, I would desire only to write to the file if it's reached below a threshold (in this case 15%) but every time I try to insert the line it's looking for a next condition, and every time I place one in it does not work.