Solved

Find didk space of C Drive in all machines in the domain

Posted on 2006-06-20
38
352 Views
Last Modified: 2008-01-09
Hi,
Need a way to find all machines in my domain for disk space less that 1 GB in C Drive.I have around 2000+ machines in my domain

This is required for all my windows updates and antivirus updates to install properly without failing.

Regards
Sharath
0
Comment
Question by:bsharath
  • 16
  • 11
  • 7
  • +2
38 Comments
 
LVL 48

Expert Comment

by:Jay_Jay70
Comment Utility
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
Nice link....

Is it possible to find from remote systems.I have 2000+ systems in which i need to find this.
0
 
LVL 48

Expert Comment

by:Jay_Jay70
Comment Utility
i am not huge on scripting myself, thats why i just posted a starting point :) can you not specify computers in that script?
0
 
LVL 29

Expert Comment

by:mass2612
Comment Utility
Hi,

This may work on remote machines if you have permissions to the remote machine. Add these lines above the strComputer line in the code Jay Jay's link contains.

InputFile = "Input.txt" ' defines name and path of file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInputFile = objFSO.OpenTextFile(InputFile) ' opens text file object
Do Until objInputFile.AtEndOfStream            ' sets beginning of loop to process all servers listed in input file

Then replace the strComputer line with this one.
strComputer = (objInputFile.Readline)      ' sets variable to read each line of input file

Create a text file with a list of all the computer hostnames that you wish to check and call it Input.txt. Save this in the dir with the script and when you run the script it should read each computer into the script and run the script against that computer.

Please note I have not tested this at all just throwing it out there for the moment. Test it on a few machines first. You should grab the list of computer names from AD.
0
 
LVL 29

Expert Comment

by:mass2612
Comment Utility
Sorry I just read through the script in Jay Jay's link and you'll need to add the word Loop to the end of it for this to work with my code above.
0
 
LVL 29

Expert Comment

by:mass2612
Comment Utility
I had a few minutes to spare and thought that a script to do this might come in handy for me sometime down the road.

This code should work assuming you have permissions to the server, working name resolution and a working network connection.

I would reocmmend running this from a command line using "cscript diskspace.vbs" - this will alllow you to monitor the processing of the script without getting the Windows popups.

Thanks to cruto.com and Jay Jay for the link.

Mods - I hope I'm not breaking any IP rules.

Diskspace.vbs
' CODE **********************************************************

Const HARD_DISK = 3
InputFile = "Input.txt" ' defines name and path of file
OutPutFile = "DiskReport.csv"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInputFile = objFSO.OpenTextFile(InputFile) ' opens text file object
Set objOutputFile = objFSO.CreateTextFile(OutputFile)
objOutputFile.WriteLine "Computer Name," & "Device," & "Free Disk Space"

Do Until objInputFile.AtEndOfStream          ' sets beginning of loop to process all servers listed in input file

strComputer = (objInputFile.Readline)
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colDisks = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalDisk Where DriveType = " & HARD_DISK & "")

For Each objDisk in colDisks
    WScript.Echo "Computer Name: " & vbtab & strComputer
    Wscript.Echo "DeviceID: "& vbTab &  objDisk.DeviceID      
    Wscript.Echo "Free Disk Space: "& vbTab & objDisk.FreeSpace/1024/1024/1024
    objOutputFile.Writeline strComputer & "," & objDisk.DeviceID & "," & objDisk.FreeSpace/1024/1024/1024
Next
Loop

' END CODE ************************************************************************
0
 
LVL 1

Expert Comment

by:grigory7811
Comment Utility
I have universal script for check of disk space on domain computers
Computers may be selected by Domain/OU, by LDAP filter or from text file. The script can notify administrators by e-mail
I'm use this script for check of disk space on servers and notify server's administrators about low disk space
The script contains some hundreds lines, can I post it here?



0
 
LVL 29

Expert Comment

by:mass2612
Comment Utility
Hi grigory7811 - do you have any good resources for learning LDAP objects, classes and queries. I've been trying to find some decent books on this topic for ages with no luck.
0
 
LVL 69

Expert Comment

by:Merete
Comment Utility
Maybe JDiskReport could help you.
JDiskReport enables you to understand how much space the files and directories consume on your disk drives, and it helps you find obsolete files and folders.
The tool analyses the disk drives and collects several statistics which you can view as overview charts and details tables
http://www.jgoodies.com/freeware/jdiskreport/index.html
Cheers Merete
0
 
LVL 1

Expert Comment

by:grigory7811
Comment Utility
mass2612 ,
I know only two good resources - rfc & msdn :)

What kind of info do you need?




0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
Hi,
mass2612

I get this error while running this script.


---------------------------
Windows Script Host
---------------------------
Script:      C:\diskspace.vbs
Line:      7
Char:      1
Error:      File not found
Code:      800A0035
Source:       Microsoft VBScript runtime error

---------------------------
OK  
---------------------------
0
 
LVL 29

Expert Comment

by:mass2612
Comment Utility
Is the Diskreport.csv file created in the directory? Check the permissions?
0
 
LVL 48

Expert Comment

by:Jay_Jay70
Comment Utility
0
 
LVL 1

Expert Comment

by:grigory7811
Comment Utility
bsharath
have you created input.txt in the same location where you run the script?
0
 
LVL 29

Expert Comment

by:mass2612
Comment Utility
grigory7811  - I was looking fir information on running ldifde queries and such against the LDAP database. I think the main thing I need to know is how the catrgories and classes work, etc.

eg. ldifide -d "dc=domain,dc=com" -r (&(objectCategory=computer)(objectclass=operatingSystem=*2003)) - I was trying to do something similar to this to pull the computer accounts running 2003 from AD and kept getting errors that objectlcass was not expected or similar.

This is where I get lost on these things. I had the same kind of issues with vbscripts until I downloaded the SDK but I can;t find much info on this LDAP stuff. I know RFC's are good but I have a hard time reading through them. I'm no programmer I'm just a admin who has learnt enough to get by writing some pretty quick and dirty code to get the job done.

If you could recommend any specific sites that would be great. Thanks.
0
 
LVL 1

Expert Comment

by:grigory7811
Comment Utility
-r parameter is LDAP search filter. Default "(objectClass=*)"

examples of filter:
(attribute=value)  - search for objects with 'attribute' equal 'value'
(!(attribute=value)) - search for objects with 'attribute' not equal 'value'
(&(attribute1=value1)(attribute=value2)) - search for objects with 'attribute1' equal 'value1' and 'attribute2' equal 'value2'
(|(attribute1=value1)(attribute=value2)) - search for objects with 'attribute1' equal 'value1' or 'attribute2' equal 'value2'
(&(attribute1=value1)(!(attribute=value2))) - search for objects with 'attribute1' equal 'value1' and 'attribute2' not equal 'value2'
etc..

value may be exact or mask with *








0
 
LVL 1

Expert Comment

by:grigory7811
Comment Utility
to make a search which you want, type:
ldifide -d "dc=domain,dc=com" -r (&(objectClass=computer)(operatingSystem=Windows Server 2003))

to obtain a complete list of possible object's attributes, use ADSI Edit MMC-console



0
 
LVL 1

Expert Comment

by:grigory7811
Comment Utility
and afraid to use mask "*value" or "*value*" on large number og objects, use only "value*"
Otherwise DC performace degradation is possible
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
Hi,

A file is created but no contents in it.
This is the error i am getting .

---------------------------
Windows Script Host
---------------------------
Script:      C:\diskspace.vbs
Line:      14
Char:      1
Error:      Permission denied: 'GetObject'
Code:      800A0046
Source:       Microsoft VBScript runtime error

---------------------------
OK  
---------------------------
Regards
Sharath
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 29

Expert Comment

by:mass2612
Comment Utility
Do you have full admin rights on the computers that are located in the input.txt file?
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
I am trying this from a domain controller machine.It has full rights on the domain
0
 
LVL 29

Expert Comment

by:mass2612
Comment Utility
Are you logged on as a member of the domain administrators group. Thats different to being logged onto a domain. Try a simple test by running the script from a workstation where you no 100% that you have full admin rights. You definately seem to have a permissions issue. The script works perfectly for me as long as I have the permissions correct.

As a test try the following: -

1. Start > Run > Regedit
2. File connect Network registry
3. Enter the name of the computer you have in the input.txt file

If this works then you probably have the correct admin rights on the remote machine.
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
Is there any thing that i have to edit in the specified file (Specific as my domain name etc.)
Any specific location from which i have to run the file.
i have saved the file with .vbs ext is it correct.

THX
Sharath
0
 
LVL 29

Expert Comment

by:mass2612
Comment Utility
Not really. You need to save the code as a vbs file in the same directory where the input.txt file you created exists. You should have full permission to read and write to this directory so that the script can open and read the input.txt file and then write the results out to the diskreport.csv file that it creates. You cannot run the script with the diskreport.csv file open as Excel will place a lock on the file. Maybe that's where you are running into problems?

Apart from that you need to have correct administration rights to the computers that you wish to obtain disk space information for. It may not be enough that you can log onto them. Certain permissions are required to obtain WMI information remotely that are different to locally. Thats why I remommend using an account with full administrator rights to the computers.

Have you tried testing it to a workstation/server that your account is a member of the local admin group?


It works fine for me.
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
Thanks all for the suggestions but these did not work still i get the error.
0
 
LVL 29

Expert Comment

by:mass2612
Comment Utility
You have some kind of permissions problem.

Try checking that DCOM is enabled on the machine you run the script from and also on the remote machine. Try this: -

Open Control Panel
Open Administrative Tools
Open the Component Services applet
Select Component Services and open the Computers Folder
Right Click My Computer and select Properties
Select the Default Properties tab and Ensure Enable Distribted COM on this Com,puter is Checked.
Apply, close all windows and reboot the PC

Please note you don't need to run the script from a domain controller. You can run it from any machine that is on the network as long as you have rights to the other machines.
0
 
LVL 29

Expert Comment

by:mass2612
Comment Utility
Have you edited these two lines at all?

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Are they ion two individual lines in your copy of the script or did you try to make them on one line or something? Are the machines on your network Windows XP or Windows 2003. I tested the script on these two OS.
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
I havent edited these 2 lines.Should i edit them?
0
 
LVL 29

Expert Comment

by:mass2612
Comment Utility
No they work fine as they are. The _ & tells the script that the second line is a continuation of the line above so if you had made them on one line it may have caused problems.

Check the DCOM stuff and let us know.
0
 
LVL 1

Expert Comment

by:grigory7811
Comment Utility
check line 7 in you script
as I see it must be      Set objInputFile = objFSO.OpenTextFile(InputFile) ' opens text file object

if it's right then the script can't find file input.txt in it's own directory

0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
this is the content which i have


Const HARD_DISK = 3
InputFile = "Input.txt" ' defines name and path of file
OutPutFile = "DiskReport.csv"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInputFile = objFSO.OpenTextFile(InputFile) ' opens text file object
Set objOutputFile = objFSO.CreateTextFile(OutputFile)
objOutputFile.WriteLine "Computer Name," & "Device," & "Free Disk Space"
Do Until objInputFile.AtEndOfStream          ' sets beginning of loop to process all servers listed in input file

strComputer = (objInputFile.Readline)
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colDisks = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalDisk Where DriveType = " & HARD_DISK & "")

For Each objDisk in colDisks
    WScript.Echo "Computer Name: " & vbtab & strComputer
    Wscript.Echo "DeviceID: "& vbTab &  objDisk.DeviceID      
    Wscript.Echo "Free Disk Space: "& vbTab & objDisk.FreeSpace/1024/1024/1024
    objOutputFile.Writeline strComputer & "," & objDisk.DeviceID & "," & objDisk.FreeSpace/1024/1024/1024
Next
Loop

And i have a input file with the name InputFile.txt with all the machine names with it.
0
 
LVL 29

Expert Comment

by:mass2612
Comment Utility
The script looks fine and I don't think that's your problem the script works. How did you get on checking the DCOM config?
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
Enable Distribted COM on this Com,puter is Checked
0
 
LVL 29

Expert Comment

by:mass2612
Comment Utility
Is this enabled on the computer you are running the script from and against?

Try these steps: -

1. Logon to a Windows XP comuter as a local administrator
2. Create a new folder c:\diskspace
3. Copy the script into the folder i.e. c:\diskspace\diskspace.vbs
4. Create a new Input.txt file and save it in c:\diskspace
5. Open the input text file and enter "localhost" without the quotes on the top line
6. Save the file
7. Open the command prompt
8. cd\diskspace
9. cscript diskspace.vbs

Tell us th result/ Sorry but I'm fast running out of things to try.
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
Great at last could do it..

The report says-

Computer Name,Device,Free Disk Space
Dev-chen-pc1100,C:,1.31223297119141
Dev-chen-pc1100,D:,8.74319839477539

can i get only for c cdrive and in GB wise not the whole thing in bytes.

THX
Sharath
0
 
LVL 29

Accepted Solution

by:
mass2612 earned 500 total points
Comment Utility
Great. It will report on any hard disk and the value is the value in GB. Use excel to open the file and format the value column to remove any decimals you don't want.

i.e. drive c has 1.3GB free
and d 8.7GB.

Open the report in Excel it's much better to read it.
0
 
LVL 11

Author Comment

by:bsharath
Comment Utility
Great it worked.What should i do not to get a dialog box just silently update the file alone.
0
 
LVL 29

Expert Comment

by:mass2612
Comment Utility
If you run thescript from the command prompt using cscript you should not get the pop ups. Otherwise you can comment out the Wscript.echo lines using a apostrophe. As below.

Const HARD_DISK = 3
InputFile = "Input.txt" ' defines name and path of file
OutPutFile = "DiskReport.csv"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInputFile = objFSO.OpenTextFile(InputFile) ' opens text file object
Set objOutputFile = objFSO.CreateTextFile(OutputFile)
objOutputFile.WriteLine "Computer Name," & "Device," & "Free Disk Space"
Do Until objInputFile.AtEndOfStream          ' sets beginning of loop to process all servers listed in input file

strComputer = (objInputFile.Readline)
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colDisks = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalDisk Where DriveType = " & HARD_DISK & "")

For Each objDisk in colDisks
'    WScript.Echo "Computer Name: " & vbtab & strComputer
 '   Wscript.Echo "DeviceID: "& vbTab &  objDisk.DeviceID      
  '  Wscript.Echo "Free Disk Space: "& vbTab & objDisk.FreeSpace/1024/1024/1024
    objOutputFile.Writeline strComputer & "," & objDisk.DeviceID & "," & objDisk.FreeSpace/1024/1024/1024
Next
Loop
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
In this article we will discuss all things related to StageFright bug, the most vulnerable bug of android devices.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now