Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-06-20
38
Medium Priority
?
364 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 16
  • 11
  • 7
  • +2
38 Comments
 
LVL 48

Expert Comment

by:Jay_Jay70
ID: 16948623
0
 
LVL 11

Author Comment

by:bsharath
ID: 16948707
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
ID: 16948712
i am not huge on scripting myself, thats why i just posted a starting point :) can you not specify computers in that script?
0
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!

 
LVL 29

Expert Comment

by:mass2612
ID: 16948876
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
ID: 16948897
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
ID: 16948954
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
ID: 16949022
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
ID: 16949608
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 70

Expert Comment

by:Merete
ID: 16949664
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
ID: 16949756
mass2612 ,
I know only two good resources - rfc & msdn :)

What kind of info do you need?




0
 
LVL 11

Author Comment

by:bsharath
ID: 16949976
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
ID: 16950621
Is the Diskreport.csv file created in the directory? Check the permissions?
0
 
LVL 48

Expert Comment

by:Jay_Jay70
ID: 16950640
0
 
LVL 1

Expert Comment

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

Expert Comment

by:mass2612
ID: 16950870
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
ID: 16951064
-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
ID: 16951106
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
ID: 16951142
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
ID: 16957213
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
 
LVL 29

Expert Comment

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

Author Comment

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

Expert Comment

by:mass2612
ID: 16958294
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
ID: 16958455
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
ID: 16958561
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
ID: 16966477
Thanks all for the suggestions but these did not work still i get the error.
0
 
LVL 29

Expert Comment

by:mass2612
ID: 16966511
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
ID: 16966528
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
ID: 16966547
I havent edited these 2 lines.Should i edit them?
0
 
LVL 29

Expert Comment

by:mass2612
ID: 16966567
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
ID: 16966646
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
ID: 16966809
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
ID: 16966845
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
ID: 16966869
Enable Distribted COM on this Com,puter is Checked
0
 
LVL 29

Expert Comment

by:mass2612
ID: 16966920
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
ID: 16966999
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 2000 total points
ID: 16967166
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
ID: 16967340
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
ID: 16968187
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

In a recent article here at Experts Exchange (http://www.experts-exchange.com/articles/18880/PaperPort-14-in-Windows-10-A-First-Look.html), I discussed my nine-month sandbox testing of the Windows 10 Technical Preview, specifically with respect to r…
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…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

604 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