[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Script/Tool for Querying Windows Disk Information

Posted on 2012-08-15
10
Medium Priority
?
778 Views
Last Modified: 2012-08-15
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.
0
Comment
Question by:waltforbes
10 Comments
 
LVL 12

Expert Comment

by:mlongoh
ID: 38296292
I can provide you with a vbscript.  Just a moment.
0
 
LVL 6

Expert Comment

by:mo_patel
ID: 38296323
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
0
 
LVL 12

Expert Comment

by:Seaton007
ID: 38296333
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 12

Expert Comment

by:mlongoh
ID: 38296336
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

0
 
LVL 12

Expert Comment

by:mlongoh
ID: 38296365
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

0
 

Author Comment

by:waltforbes
ID: 38296498
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.
0
 
LVL 12

Accepted Solution

by:
mlongoh earned 2000 total points
ID: 38296547
Save this batch file as GetDiskSpace.cmd and populate a text file called GetDiskSpace.txt with the list of server names.  Then run GetDiskSpace.cmd.  It will run the vbscript against every server name in the list.

FOR /F "eol=# tokens=1-8 delims=*" %%i IN (GetDiskSpace.txt) DO cscript GetDiskSpace.vbs %%i

Open in new window

0
 

Author Comment

by:waltforbes
ID: 38296690
To mlongoh: Wow! You're amazing..., and I am sooo grateful. Thank you.
0
 
LVL 12

Expert Comment

by:mlongoh
ID: 38296722
Glad to help.
0
 

Author Closing Comment

by:waltforbes
ID: 38296740
You have delivered! Life just got more pleasant!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The business world is becoming increasingly integrated with tech. It’s not just for a select few anymore — but what about if you have a small business? It may be easier than you think to integrate technology into your small business, and it’s likely…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
This video teaches viewers how to encrypt an external drive that requires a password to read and edit the drive. All tasks are done in Disk Utility. Plug in the external drive you wish to encrypt: Make sure all previous data on the drive has been …

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question