Link to home
Start Free TrialLog in
Avatar of waltforbes
waltforbesFlag for Bahamas

asked on

Script/Tool for Querying Windows Disk Information

Points of My Scenario:
1. I am admin for a Windows domain
2. Server 2003 and Server 2008 machines are in the domain
3. I must report on the storage of 100+ Windows servers - number of partitions, size of partitions, and used space.
QUESTION:
I need a script of utility that can remotely query multiple servers at a time and can output results to a spreadsheet, CSV, HTML or MHT file.
Avatar of mlongoh
mlongoh
Flag of United States of America image

I can provide you with a vbscript.  Just a moment.
Avatar of mo_patel
mo_patel

http://community.spiceworks.com/scripts/show/1074-powershell-script-to-check-free-disk-spaces-for-servers

check out this, it will read all server names from a txt file and out out to excel
Avatar of Seaton007
Here's a script that will report logical drives and space information.  It can be adjusted to output to a text file pretty easily.

strComputer = wscript.arguments(0)
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalDisk")
'    ("Select * from Win32_LogicalDisk Where DeviceID = 'C:'")
For Each objDisk in colDisks
	If NOT IsNull(objDisk.Size) Then
		intFreeSpace = objDisk.FreeSpace
		intTotalSpace = objDisk.Size
		intUsedSpace = objDisk.Size - objDisk.FreeSpace
		percent = intTotalSpace * 0.1
		wscript.echo strComputer
		wscript.echo objDisk.DeviceID & " " & ROUND(intTotalSpace/1024/1024/1024,2) & " GB Total"
		wscript.echo objDisk.DeviceID & " " & ROUND(intUsedSpace/1024/1024/1024,2) & " GB In Use"
		wscript.echo objDisk.DeviceID & " " & ROUND(intFreeSpace/1024/1024/1024,2) & " GB Free"
	End If
Next

Open in new window

Here it is revised to log to a file called GetDiskSpace.log.  Save the attached code as GetDiskSpace.vbs and run it like this:
cscript GetDiskSpace.vbs servername

The output is tab delimited and can be imported into Excel if you wish.

strComputer = wscript.arguments(0)
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalDisk")
'    ("Select * from Win32_LogicalDisk Where DeviceID = 'C:'")
For Each objDisk in colDisks
	If NOT IsNull(objDisk.Size) Then
		intFreeSpace = objDisk.FreeSpace
		intTotalSpace = objDisk.Size
		intUsedSpace = objDisk.Size - objDisk.FreeSpace
		percent = intTotalSpace * 0.1
		wscript.echo strComputer
		wscript.echo objDisk.DeviceID & " " & ROUND(intTotalSpace/1024/1024/1024,2) & " GB Total"
		wscript.echo objDisk.DeviceID & " " & ROUND(intUsedSpace/1024/1024/1024,2) & " GB In Use"
		wscript.echo objDisk.DeviceID & " " & ROUND(intFreeSpace/1024/1024/1024,2) & " GB Free"
		LogMe strComputer & vbtab & objDisk.DeviceID & " " & ROUND(intTotalSpace/1024/1024/1024,2) & " GB Total" & vbtab & objDisk.DeviceID & " " & ROUND(intUsedSpace/1024/1024/1024,2) & " GB In Use" & vbtab & objDisk.DeviceID & " " & ROUND(intFreeSpace/1024/1024/1024,2) & " GB Free", "GetDiskSpace.log"
	End If
Next

Function LogMe(LogInfo, LogFile)
	Set mdlfso = CreateObject("Scripting.FileSystemObject")
	Set mtf = mdlfso.OpenTextFile(LogFile, 8, True)
	mtf.WriteLine (LogInfo)
	mtf.Close
End Function

Open in new window

Avatar of waltforbes

ASKER

To mlongoh: I need to specify 100 servers to your script so that the output file (GetDiskSpace.log) contains results for all the servers. How to do this?

To mo_patel: when I attempt to run the script in powershell, a popup appears requesting me to choose a program to open the file. I saved the script with extension ".pl" using notepad.
ASKER CERTIFIED SOLUTION
Avatar of mlongoh
mlongoh
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To mlongoh: Wow! You're amazing..., and I am sooo grateful. Thank you.
Glad to help.
You have delivered! Life just got more pleasant!