bsharath
asked on
Find didk space of C Drive in all machines in the domain
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
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
ASKER
Nice link....
Is it possible to find from remote systems.I have 2000+ systems in which i need to find this.
Is it possible to find from remote systems.I have 2000+ systems in which i need to find this.
i am not huge on scripting myself, thats why i just posted a starting point :) can you not specify computers in that script?
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.Fi leSystemOb ject")
Set objInputFile = objFSO.OpenTextFile(InputF ile) ' 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.
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.Fi
Set objInputFile = objFSO.OpenTextFile(InputF
Do Until objInputFile.AtEndOfStream
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.
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.
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.Fi leSystemOb ject")
Set objInputFile = objFSO.OpenTextFile(InputF ile) ' opens text file object
Set objOutputFile = objFSO.CreateTextFile(Outp utFile)
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=imper sonate}!\\ " & 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/102 4/1024
objOutputFile.Writeline strComputer & "," & objDisk.DeviceID & "," & objDisk.FreeSpace/1024/102 4/1024
Next
Loop
' END CODE ************************** ********** ********** ********** ********** ******
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.Fi
Set objInputFile = objFSO.OpenTextFile(InputF
Set objOutputFile = objFSO.CreateTextFile(Outp
objOutputFile.WriteLine "Computer Name," & "Device," & "Free Disk Space"
Do Until objInputFile.AtEndOfStream
strComputer = (objInputFile.Readline)
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper
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/102
objOutputFile.Writeline strComputer & "," & objDisk.DeviceID & "," & objDisk.FreeSpace/1024/102
Next
Loop
' END CODE **************************
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?
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?
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.
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
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
mass2612 ,
I know only two good resources - rfc & msdn :)
What kind of info do you need?
I know only two good resources - rfc & msdn :)
What kind of info do you need?
ASKER
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
-------------------------- -
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
--------------------------
Is the Diskreport.csv file created in the directory? Check the permissions?
bsharath
have you created input.txt in the same location where you run the script?
have you created input.txt in the same location where you run the script?
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 )(objectcl ass=operat ingSystem= *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.
eg. ldifide -d "dc=domain,dc=com" -r (&(objectCategory=computer
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.
-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)(attr ibute=valu e2)) - search for objects with 'attribute1' equal 'value1' and 'attribute2' equal 'value2'
(|(attribute1=value1)(attr ibute=valu e2)) - search for objects with 'attribute1' equal 'value1' or 'attribute2' equal 'value2'
(&(attribute1=value1)(!(at tribute=va lue2))) - search for objects with 'attribute1' equal 'value1' and 'attribute2' not equal 'value2'
etc..
value may be exact or mask with *
examples of filter:
(attribute=value) - search for objects with 'attribute' equal 'value'
(!(attribute=value)) - search for objects with 'attribute' not equal 'value'
(&(attribute1=value1)(attr
(|(attribute1=value1)(attr
(&(attribute1=value1)(!(at
etc..
value may be exact or mask with *
to make a search which you want, type:
ldifide -d "dc=domain,dc=com" -r (&(objectClass=computer)(o peratingSy stem=Windo ws Server 2003))
to obtain a complete list of possible object's attributes, use ADSI Edit MMC-console
ldifide -d "dc=domain,dc=com" -r (&(objectClass=computer)(o
to obtain a complete list of possible object's attributes, use ADSI Edit MMC-console
and afraid to use mask "*value" or "*value*" on large number og objects, use only "value*"
Otherwise DC performace degradation is possible
Otherwise DC performace degradation is possible
ASKER
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
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
Do you have full admin rights on the computers that are located in the input.txt file?
ASKER
I am trying this from a domain controller machine.It has full rights on the domain
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.
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.
ASKER
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
Any specific location from which i have to run the file.
i have saved the file with .vbs ext is it correct.
THX
Sharath
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.
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.
ASKER
Thanks all for the suggestions but these did not work still i get the error.
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.
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.
Have you edited these two lines at all?
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper sonate}!\\ " & 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.
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper
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.
ASKER
I havent edited these 2 lines.Should i edit them?
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.
Check the DCOM stuff and let us know.
check line 7 in you script
as I see it must be Set objInputFile = objFSO.OpenTextFile(InputF ile) ' opens text file object
if it's right then the script can't find file input.txt in it's own directory
as I see it must be Set objInputFile = objFSO.OpenTextFile(InputF
if it's right then the script can't find file input.txt in it's own directory
ASKER
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.Fi leSystemOb ject")
Set objInputFile = objFSO.OpenTextFile(InputF ile) ' opens text file object
Set objOutputFile = objFSO.CreateTextFile(Outp utFile)
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=imper sonate}!\\ " & 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/102 4/1024
objOutputFile.Writeline strComputer & "," & objDisk.DeviceID & "," & objDisk.FreeSpace/1024/102 4/1024
Next
Loop
And i have a input file with the name InputFile.txt with all the machine names with it.
Const HARD_DISK = 3
InputFile = "Input.txt" ' defines name and path of file
OutPutFile = "DiskReport.csv"
Set objFSO = CreateObject("Scripting.Fi
Set objInputFile = objFSO.OpenTextFile(InputF
Set objOutputFile = objFSO.CreateTextFile(Outp
objOutputFile.WriteLine "Computer Name," & "Device," & "Free Disk Space"
Do Until objInputFile.AtEndOfStream
strComputer = (objInputFile.Readline)
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper
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/102
objOutputFile.Writeline strComputer & "," & objDisk.DeviceID & "," & objDisk.FreeSpace/1024/102
Next
Loop
And i have a input file with the name InputFile.txt with all the machine names with it.
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?
ASKER
Enable Distribted COM on this Com,puter is Checked
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.
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.
ASKER
Great at last could do it..
The report says-
Computer Name,Device,Free Disk Space
Dev-chen-pc1100,C:,1.31223 297119141
Dev-chen-pc1100,D:,8.74319 839477539
can i get only for c cdrive and in GB wise not the whole thing in bytes.
THX
Sharath
The report says-
Computer Name,Device,Free Disk Space
Dev-chen-pc1100,C:,1.31223
Dev-chen-pc1100,D:,8.74319
can i get only for c cdrive and in GB wise not the whole thing in bytes.
THX
Sharath
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great it worked.What should i do not to get a dialog box just silently update the file alone.
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.Fi leSystemOb ject")
Set objInputFile = objFSO.OpenTextFile(InputF ile) ' opens text file object
Set objOutputFile = objFSO.CreateTextFile(Outp utFile)
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=imper sonate}!\\ " & 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/102 4/1024
objOutputFile.Writeline strComputer & "," & objDisk.DeviceID & "," & objDisk.FreeSpace/1024/102 4/1024
Next
Loop
Const HARD_DISK = 3
InputFile = "Input.txt" ' defines name and path of file
OutPutFile = "DiskReport.csv"
Set objFSO = CreateObject("Scripting.Fi
Set objInputFile = objFSO.OpenTextFile(InputF
Set objOutputFile = objFSO.CreateTextFile(Outp
objOutputFile.WriteLine "Computer Name," & "Device," & "Free Disk Space"
Do Until objInputFile.AtEndOfStream
strComputer = (objInputFile.Readline)
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper
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/102
objOutputFile.Writeline strComputer & "," & objDisk.DeviceID & "," & objDisk.FreeSpace/1024/102
Next
Loop
http://www.cruto.com/resources/vbscript/vbscript-examples/storage/disks/drives/List-Available-Disk-Space.asp