mini-computer inventory

  • Thread starter Cary Shultz [A.D. MVP]
  • Start date
C

Cary Shultz [A.D. MVP]

Good afternoon!

Running WIN2000 Server SP4 Active Directory with WIN2000 Pro SP4 and WINXP
Pro SP1 and SP2 clients. I hope that this is the correct newsgroup. I am
thinking that it is not, based on the name of this newsgroup.

I am a complete newbie when it comes to scripting. So, please be patient.
And please pardon my possible incorrect use of terms.

I am learning WMI and ADSI ( for the purposes of making Systems
Administration a whole lot easier ). What I am trying to find is a simple
way to run a script that will, for this example, compile a list of the
Operating System and Service Pack of all the computers in the domain. I
know that I can easily do this via ldifde ( and do it all the time ) but I
am going to want to do this for RAM, CPU and Hard Drive soon - and ldifde
can not do this. WMI can, though.

Anyway, it seems that all of the examples that I have seen are for running
against the local machine ( strComputer = ".", which is not too bad... ) or
against one, specific remote host ( strComputer = "atl-ws-01" ) . I would
need this to run against all of the computers in the domain. Another
problem is that the 'result' is usually echoed to the screen ( WScript.Echo
objItem.Property ). This does not help when I have hundreds and hundreds of
computers! I would like one single .txt file that contains the information
from all of the computers in the domain. Is this possible?

Thank you all for your suggestions and time!

Cary
 
P

Peter Falz

Hi Cary Shultz [A.D. MVP],

Cary Shultz said:
Anyway, it seems that all of the examples that I have seen are for running
against the local machine ( strComputer = ".", which is not too bad... ) or
against one, specific remote host ( strComputer = "atl-ws-01" ) . I would
need this to run against all of the computers in the domain. Another
problem is that the 'result' is usually echoed to the screen ( WScript.Echo
objItem.Property ). This does not help when I have hundreds and hundreds of
computers! I would like one single .txt file that contains the information
from all of the computers in the domain. Is this possible?

You have a list as type of a textfile of all computer the script should
run against?

It is not a problem, that the result can be written to a textfile.
Therefore, you have to use FileScriptingObject.

Your question: Is this possible? Yes, it is.

Cioa
Peter
 
C

Cary Shultz [A.D. MVP]

Peter,

Thank you. Could you give me an example? Let's just say that I had a .txt
file ( probably not a problem to create ) with all of the computer account
objects. How would it look? Sorry, but really a newbie and have spent all
of six hours with this so far.

Thank you,

Cary

Peter Falz said:
Hi Cary Shultz [A.D. MVP],

Anyway, it seems that all of the examples that I have seen are for running
against the local machine ( strComputer = ".", which is not too bad... ) or
against one, specific remote host ( strComputer = "atl-ws-01" ) . I would
need this to run against all of the computers in the domain. Another
problem is that the 'result' is usually echoed to the screen ( WScript.Echo
objItem.Property ). This does not help when I have hundreds and hundreds of
computers! I would like one single .txt file that contains the information
from all of the computers in the domain. Is this possible?

You have a list as type of a textfile of all computer the script should
run against?

It is not a problem, that the result can be written to a textfile.
Therefore, you have to use FileScriptingObject.

Your question: Is this possible? Yes, it is.

Cioa
Peter
 
P

Peter Falz

Hi Cary,

Cary Shultz said:
Thank you. Could you give me an example? Let's just say that I had a .txt
file ( probably not a problem to create ) with all of the computer account
objects. How would it look? Sorry, but really a newbie and have spent all
of six hours with this so far.

i've known, that you ask for this and i've coded just yesterday the
following lines for "you" ;-).

' --- Code: Begin
Const OPENFORREAD = 1

Dim dicComputer
Set dicComputer = CreateObject( "Scripting.Dictionary" )

Dim objFSO
Set objFSO = CreateObject( "Scripting.FileSystemObject" )

Dim objFILE_Input
Set objFILE_Input = objfso.OpenTextFile( "computer.txt" , OPENFORREAD )
Dim objFILE_Result
Set objFILE_Result = objFSO.CreateTextFile( "result.txt" , True )

Dim objWMI
Dim objWMIInstance

Dim strComputer
Dim strResult

Dim intKey
Dim intCount
intCount = 0


' --- Read the file and create a dictionary.
' --- Can be used, if the computerlist must be looped more than one time
Do While Not objFILE_Input.AtEndOfStream
intCount = intCount + 1

strComputer = objFILE_Input.ReadLine
dicComputer.add intCount , strComputer
Loop


Set objFILE_Input = Nothing


For Each intKey In dicComputer
strComputer = dicComputer.Item( intKey )

On Error Resume Next

Set objWMI = GetObject( "winmgmts:\\" & strComputer & "\root\cimv2" )

If ERR = 0 Then
' --- This For/Each runs one time
For Each objWMIInstance In objWMI.InstancesOf( "Win32_ComputerSystem" )
strResult = vbCrLf & "[" & objWMIInstance.Name & "]"
objFILE_Result.WriteLine strResult
Next 'objWMIInstance

For Each objWMIInstance In objWMI.InstancesOf( "Win32_DiskDrive" )
objFILE_Result.WriteLine objWMIInstance.Caption
Next 'objWMIInstance
End If

Set objWMI = Nothing

On Error Goto 0
Next


Set objFILE_Result = Nothing
Set objFSO = Nothing

' --- Code: Ended

The inputfile have to be named as "computer.txt".
The resultfile is named as "result.txt".
I've tested this script with "cscript" and in works fine.
Importent is, that you have the rights on the remote computer
to do these actions, to run WMI.

HTH

Cioa
Peter
 
C

Cary Shultz [A.D. MVP]

Guten Morgen Peter,

Ich bedanke mich recht herzlich bei Dir fuer Deine Hilfe! Ich werde mir den
Text ansehen and davon lernen!

I am really not having the time that I would like to have for this. And by
'for this' I mean rolling up my sleeves and really learning WMI so that I
can come up with this sort of thing on my own. The bottom half looks
familiar and very understandable. I would - at this point - not be able to
have come up with the top half.....Not yet! But that will change. I will
learn WMI and ADSI. There are too many things that you can do with both of
them that make my job so much easier!

I hope that everyone in this newsgroup will benefit from this example! And,
when using it, give Peter due credit.

Best regards,

Cary



Peter Falz said:
Hi Cary,

Thank you. Could you give me an example? Let's just say that I had a ..txt
file ( probably not a problem to create ) with all of the computer account
objects. How would it look? Sorry, but really a newbie and have spent all
of six hours with this so far.

i've known, that you ask for this and i've coded just yesterday the
following lines for "you" ;-).

' --- Code: Begin
Const OPENFORREAD = 1

Dim dicComputer
Set dicComputer = CreateObject( "Scripting.Dictionary" )

Dim objFSO
Set objFSO = CreateObject( "Scripting.FileSystemObject" )

Dim objFILE_Input
Set objFILE_Input = objfso.OpenTextFile( "computer.txt" , OPENFORREAD )
Dim objFILE_Result
Set objFILE_Result = objFSO.CreateTextFile( "result.txt" , True )

Dim objWMI
Dim objWMIInstance

Dim strComputer
Dim strResult

Dim intKey
Dim intCount
intCount = 0


' --- Read the file and create a dictionary.
' --- Can be used, if the computerlist must be looped more than one time
Do While Not objFILE_Input.AtEndOfStream
intCount = intCount + 1

strComputer = objFILE_Input.ReadLine
dicComputer.add intCount , strComputer
Loop


Set objFILE_Input = Nothing


For Each intKey In dicComputer
strComputer = dicComputer.Item( intKey )

On Error Resume Next

Set objWMI = GetObject( "winmgmts:\\" & strComputer & "\root\cimv2" )

If ERR = 0 Then
' --- This For/Each runs one time
For Each objWMIInstance In objWMI.InstancesOf( "Win32_ComputerSystem" )
strResult = vbCrLf & "[" & objWMIInstance.Name & "]"
objFILE_Result.WriteLine strResult
Next 'objWMIInstance

For Each objWMIInstance In objWMI.InstancesOf( "Win32_DiskDrive" )
objFILE_Result.WriteLine objWMIInstance.Caption
Next 'objWMIInstance
End If

Set objWMI = Nothing

On Error Goto 0
Next


Set objFILE_Result = Nothing
Set objFSO = Nothing

' --- Code: Ended

The inputfile have to be named as "computer.txt".
The resultfile is named as "result.txt".
I've tested this script with "cscript" and in works fine.
Importent is, that you have the rights on the remote computer
to do these actions, to run WMI.

HTH

Cioa
Peter
 
P

Peter Falz

Hi Cary,

Cary Shultz said:
Guten Morgen Peter,
Ich bedanke mich recht herzlich bei Dir fuer Deine Hilfe! Ich werde mir den
Text ansehen and davon lernen!
Wow, in German, top!
I am really not having the time that I would like to have for this. And by
'for this' I mean rolling up my sleeves and really learning WMI so that I
can come up with this sort of thing on my own. The bottom half looks
familiar and very understandable. I would - at this point - not be able to
have come up with the top half.....Not yet! But that will change. I will
What's the problem? Much code with not so much benefit? Of course,
it is not necessary to do it so as i've done here, but that's way, we are
programming, and that's to use a very "clean way". (i hope you understand
what i want to say, my english is not the best).
learn WMI and ADSI. There are too many things that you can do with both of
them that make my job so much easier!
Yes, you have right, also ADSI makes the job easiar. But with this i have no
expirience, not yet ;-).
I hope that everyone in this newsgroup will benefit from this example! And,
when using it, give Peter due credit.
Thx.

Ciao
Peter
 
C

Cary Shultz [A.D. MVP]

Peter,

Lived in Ruesselsheim for a couple of years and worked in Floersheim during
that time. Also spent several months in the Bonn / Koeln area learning
German. It has been some 10 years since I came back to the US ( March
1995 ) but have not forgotten too much. Actually spoke with some Germans
here in Roanoke, VA the other day and was pleasantly surprised that
everything still flows. It took a second initially but that was the only
delay.

And, to comment on your code - just not familiar with it. The style is a
bit different from what I have seen ( pretty much -ONLY- the Scripting Guys
webcasts ) but that is not the problem. Just not familiar with this. Not
yet! But I am sure that in a couple of days or weeks it will seem perfectly
familiar! And I always prefer to do it the clean, correct way rather than
use a bunch of shortcuts.

And so far I have had no problems whatsoever in any of your posts with your
English.....it is quite good, infact!

Thank you, again!

Cary
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top