Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Gathering Hardware Information?

Status
Not open for further replies.

parasomia

Technical User
Mar 11, 2010
8
US
Hey everyone,

I'm new to scripting and I am really trying to learn quite a bit from it. I just don't have a ton of time, but do need a script quickly.

I've searched around and found bits and pieces but not quite what I would like to achieve.

Basically, I'd like to query WMI and gather hardware information from machines on my domain. The script should have a command line argument so I can input which machine to gather it from. I'm thinking having OS information would be nice as well along with bios, cpu, hard disk, and ram information. Perhaps its possible to list other installed hardware? Such as the graphics card, network adapters, dvd drives?

It would be really nice to have a script that can pull this information from the machines in my domain and output them into a text file. Is it also possible to pull driver information for the hardware as well?

If anyone can help out - Very many thanks in advance!
 
I don't have a pre-written script to do it, but for a more general answer, I recommend the Scriptomatic tool from Microsoft:

It is a user interface that lets you explore the numerous WMI classes available, gives you sample scripts and lets you execute them in a single click so you can see the output, and see if it gives you what you need.

I would start with Win32_ComputerSystem, Win32_OperatingSystem, Win32_LogicalDisk

As for command line parameters, use WScript.Arguments, explained here:
 
Thank you for the quick response guitarzan.

Using Scriptomatic would be great but there is a problem. As soon as I open it, it tells me "An error has occurred in the script on this page". Line 177 Char 4 Error: Could not complete the operation due to error 80041003. Code 0"

I've tried running it in Windows 7 and in Windows Server 2003. I am the admin in both cases. It would be a lovely tool to help out if I could figure out the problem.. which is probably something simple.
 
Hmmm... it works fine for me in Server 2003 (with administrator account... won't work with Power User or less).

The link below implies that you may have problems with UAC on Vista/7, and the way around that (according to this page) is to launch an elevated command prompt and type:
MSHTA.EXE C:\<path to Scriptomatic>\ScriptomaticV2.HTA

 
guitarzan,

thanks again for the quick response. I tried that under Windows 7 and it still acts the same way. I also double checked in my VM of Windows Server 2003 and in Windows 7 if I am the administrator, and I am.

Very strange. I wish I could get this figured out because I think scriptomatic would really help in my cause.
 
Alright,

So I managed to get a lot of script information that I would need. Scriptomatic is just not working for me so maybe someone here can help me piece this all together.

I found a nice script on these forums that does a lot that I want. I would like to take out the part where it looks for processes running on the computer. I don't need that. I would like to add in for it to pull some bios and graphics info. The only other thing I would like to modify on it would be for it to have a command like argument so I can choose what machine on a domain to check (Like, Cscript hardware.vbs machine1,machine2,machine3)

If anyone could help me piece this together because .. yea I'm pretty much clueless.

Here is the script that I found on these forums:

On Error Resume Next


Set oShell = CreateObject("wscript.Shell")
Set env = oShell.environment("Process")
strComputer = env.Item("Computername")
Const HKEY_LOCAL_MACHINE = &H80000002
Const UnInstPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
".\root\default:StdRegProv")


report = strComputer & " Computer Inventory" & vbCrLf & "******************************************" & vbCrLf & vbCrLf
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)

report = report & vbCrLf & "******************************************" & vbCrLf
report = report & "OS Information" & vbCrLf & "******************************************" & vbCrLf & vbCrLf
For Each objItem in colItems
report = report & "Caption: " & objItem.Caption & vbCrLf
report = report & "Description: " & objItem.Description & vbCrLf
report = report & "EncryptionLevel: " & objItem.EncryptionLevel & vbCrLf
report = report & "InstallDate: " & objItem.InstallDate & vbCrLf
report = report & "Manufacturer: " & objItem.Manufacturer & vbCrLf
report = report & "MaxNumberOfProcesses: " & objItem.MaxNumberOfProcesses & vbCrLf
report = report & "Name: " & objItem.Name & vbCrLf
report = report & "Organization: " & objItem.Organization & vbCrLf
report = report & "OSProductSuite: " & objItem.OSProductSuite & vbCrLf
report = report & "RegisteredUser: " & objItem.RegisteredUser & vbCrLf
report = report & "SerialNumber: " & objItem.SerialNumber & vbCrLf
report = report & "ServicePackMajorVersion: " & objItem.ServicePackMajorVersion
report = report & "ServicePackMinorVersion: " & objItem.ServicePackMinorVersion & vbCrLf
report = report & "Version: " & objItem.Version & vbCrLf
report = report & "WindowsDirectory: " & objItem.WindowsDirectory & vbCrLf
Next

Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
report = report & vbCrLf & "******************************************" & vbCrLf
report = report & "Memory and Processor Information" & vbCrLf & "******************************************" & vbCrLf & vbCrLf
For Each objComputer in colSettings
'report = report & objComputer.Name & vbcrlf
report = report & objComputer.TotalPhysicalMemory /1024\1024+1 & "MB Total memory" & vbcrlf
Next
Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_Processor")
For Each objProcessor in colSettings
report = report & objProcessor.Description & " Processor" & vbCrLf
Next

Set cInstances = GetObject("winmgmts:{impersonationLevel=impersonate}//" &_
strComputer & "/root/cimv2:Win32_Service").Instances_
'********************************
'*** Enumerate instances in the loop, for each, list relevant properties
report = report & vbCrLf & "******************************************" & vbCrLf
report = report & "Services" & vbCrLf & "******************************************" & vbCrLf & vbCrLf
For Each oInstance In cInstances
report = report & "Name:" & vbTab & vbTab & oInstance.Properties_("Name").Value & vbCrLf
report = report & "DisplayName:" & vbTab & oInstance.Properties_("DisplayName").Value & vbCrLf
report = report & "StartMode:" & vbTab & oInstance.Properties_("StartMode").Value & vbCrLf
report = report & "State:" & vbTab & vbTab & oInstance.Properties_("State").Value & vbCrLf
Next


report = report & vbCrLf & "******************************************" & vbCrLf
report = report & "Disk Drive Information" & vbCrLf & "******************************************" & vbCrLf & vbCrLf

Set objWMIService = GetObject("winmgmts:")
Set objLogicalDisk = objWMIService.Get("Win32_LogicalDisk.DeviceID='c:'")
report = report & objLogicalDisk.FreeSpace /1024\1024+1 & "MB Free Disk Space" & vbCrLf
report = report & objLogicalDisk.Size /1024\1024+1 & "MB Total Disk Space" & vbCrLf

oReg.EnumKey HKEY_LOCAL_MACHINE, UnInstPath, arrSubKeys
software = software & vbCrLf & "******************************************" & vbCrLf
software = software & "Installed Software" & vbCrLf & "******************************************" & vbCrLf & vbCrLf
For Each subkey In arrSubKeys
'MsgBox subkey
If Left (subkey, 1) <> "{" Then
software = software & subkey & vbCrLf
End If
Next

Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile (strComputer & ".txt", ForWriting)
ts.write report
ts.write software
'MsgBox Report
MsgBox "Done"
------------------------------------------------------------


Most of that helps a good bit, except as I've said, I'd like to take out the processes part of it and add in a bios and graphics card inventory. I'd still like it to output to the text file, that is great.

What I've found for the Bios and Graphics:

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

Set colBIOS = objWMIService.ExecQuery _
("Select * from Win32_BIOS")

For each objBIOS in colBIOS
Wscript.Echo "Build Number: " & objBIOS.BuildNumber
Wscript.Echo "Current Language: " & objBIOS.CurrentLanguage
Wscript.Echo "Installable Languages: " & objBIOS.InstallableLanguages
Wscript.Echo "Manufacturer: " & objBIOS.Manufacturer
Wscript.Echo "Name: " & objBIOS.Name
Wscript.Echo "Primary BIOS: " & objBIOS.PrimaryBIOS
Wscript.Echo "Release Date: " & objBIOS.ReleaseDate
Wscript.Echo "Serial Number: " & objBIOS.SerialNumber
Wscript.Echo "SMBIOS Version: " & objBIOS.SMBIOSBIOSVersion
Wscript.Echo "SMBIOS Major Version: " & objBIOS.SMBIOSMajorVersion
Wscript.Echo "SMBIOS Minor Version: " & objBIOS.SMBIOSMinorVersion
Wscript.Echo "SMBIOS Present: " & objBIOS.SMBIOSPresent
Wscript.Echo "Status: " & objBIOS.Status
Wscript.Echo "Version: " & objBIOS.Version
For i = 0 to Ubound(objBIOS.BiosCharacteristics)
Wscript.Echo "BIOS Characteristics: " & _
objBIOS.BiosCharacteristics(i)
Next
Next
---------------------------------------------------------

and for the video


Set colItems = objWMIService.ExecQuery( "Select * from Win32_VideoController", , 48 )
' Display error number and description if applicable
If Err Then ShowError
' Prepare display of results
For Each objItem in colItems
strMsg = strMsg & "Video" & vbCrLf _
& " Name: " _
& objItem.Name & vbCrLf _
& " Description: " _
& objItem.Description & vbCrLf _
& " Video Processor: " _
& objItem.VideoProcessor & vbCrLf _
& " Adapter RAM: " _
& Int( ( objItem.AdapterRAM + 524288 ) / 1048576 ) _
& " MB" & vbCrLf _
& " Video Mode Description: " _
& objItem.VideoModeDescription & vbCrLf & vbCrLf
Next
----------------------------------------------------------

Okay, this is a lot of stuff. I'm just wondering if anyone can help put it together. This would be a great script. I've tried a few things but I'm not getting anywhere.

Thank you

 
Because the first part is written to a file, you might as well print the rest to the file.

First, copy all chuncks of code into a new VBS file. The end of the first defines an output text file handle and designates it as "ts" in the line
Code:
Set ts = fso.CreateTextFile (strComputer & ".txt", ForWriting)
. To add the output of the other two chunks of code (BIOS and VideoController), simply redirect the output from the screen (Echo) to the file handle, ts. In BIOS, change "Wscript.Echo" to "ts.WriteLine". Also, in VideoController, change "strMsg = strMsg &" to "ts.WriteLine".

At the very bottom of the script, add "ts.close" to unmount the file handle.

To allows for arguments, make use of the Args object. Cycle through the arguments and parse what you need. You can either pass arguments statically or dynamically using switches.

statically - access each argument like an array
Code:
set objArgs = WScript.Arguments
strComputer = objArgs(0)
strFile = objArgs(1)
boolViewFile = objArgs(2)

'usage
audit.vbs finance1 c:\finance1_audit.txt 1

dynamically using switches (prefered because it give you more flexability at the cmdline.
Code:
set objArgs = WScript.Arguments
for i = 0 to objArgs.count
   select case objArgs(i)
      case "/c" : strComputer = objArgs(i + 1)
      case "/f" : strFile = objArgs(i + 1)
      case "/v" : boolViewFile = true
   end select
next

'usage
audit.vbs /c finance1 /f c:\finance1_audit.txt /v
audit.vbs /c finance1

Adding random blocks of code like this is a bad practice. This is a very crude merge of code and should be rewritten when you have the time. I have been tweeking mine since it was first written (March 2008). Here's a version of mine for Summer 2009

-Geates
 
Hi Geates,

Thanks for the quick reply. Your advice actually helped even though I had to go about it a different way. But it got me thinking, which was great.

I tried what you said about outputting to the file by changing those lines for the Bios and Video. However, it still wasn't outputting it. So I thought about it and tried to integrate it with how the script was setup. It was successful! I can now get all the information written to a text file. I even took out the processes. Now it looks more like the script instead of bits and pieces thrown in.

--------------
On Error Resume Next


Set oShell = CreateObject("wscript.Shell")
Set env = oShell.environment("Process")
strComputer = env.Item("Computername")
Const HKEY_LOCAL_MACHINE = &H80000002
Const UnInstPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
".\root\default:StdRegProv")



report = strComputer & " Computer Inventory" & vbCrLf & "******************************************" & vbCrLf & vbCrLf
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)

report = report & vbCrLf & "******************************************" & vbCrLf
report = report & "OS Information" & vbCrLf & "******************************************" & vbCrLf & vbCrLf
For Each objItem in colItems
report = report & "Caption: " & objItem.Caption & vbCrLf
report = report & "Description: " & objItem.Description & vbCrLf
report = report & "EncryptionLevel: " & objItem.EncryptionLevel & vbCrLf
report = report & "InstallDate: " & objItem.InstallDate & vbCrLf
report = report & "Manufacturer: " & objItem.Manufacturer & vbCrLf
report = report & "MaxNumberOfProcesses: " & objItem.MaxNumberOfProcesses & vbCrLf
report = report & "Name: " & objItem.Name & vbCrLf
report = report & "Organization: " & objItem.Organization & vbCrLf
report = report & "OSProductSuite: " & objItem.OSProductSuite & vbCrLf
report = report & "RegisteredUser: " & objItem.RegisteredUser & vbCrLf
report = report & "SerialNumber: " & objItem.SerialNumber & vbCrLf
report = report & "ServicePackMajorVersion: " & objItem.ServicePackMajorVersion
report = report & "ServicePackMinorVersion: " & objItem.ServicePackMinorVersion & vbCrLf
report = report & "Version: " & objItem.Version & vbCrLf
report = report & "WindowsDirectory: " & objItem.WindowsDirectory & vbCrLf
Next



Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
report = report & vbCrLf & "******************************************" & vbCrLf
report = report & "Memory and Processor Information" & vbCrLf & "******************************************" & vbCrLf & vbCrLf
For Each objComputer in colSettings
'report = report & objComputer.Name & vbcrlf
report = report & objComputer.TotalPhysicalMemory /1024\1024+1 & "MB Total memory" & vbcrlf
Next
Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_Processor")
For Each objProcessor in colSettings
report = report & objProcessor.Description & " Processor" & vbCrLf
Next

report = report & vbCrLf & "******************************************" & vbCrLf
report = report & "BIOS" & vbCrLf & "******************************************" & vbCrLf & vbCrLf

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

Set colBIOS = objWMIService.ExecQuery _
("Select * from Win32_BIOS")

For each objBIOS in colBIOS
report = report & "Build Number: " & objBIOS.BuildNumber & vbCrLf
report = report & "Current Language: " & objBIOS.CurrentLanguage & vbCrLf
report = report & "Installable Languages: " & objBIOS.InstallableLanguages & vbCrLf
report = report & "Manufacturer: " & objBIOS.Manufacturer & vbCrLf
report = report & "Name: " & objBIOS.Name & vbCrLf
report = report & "Primary BIOS: " & objBIOS.PrimaryBIOS & vbCrLf
report = report & "Release Date: " & objBIOS.ReleaseDate & vbCrLf
report = report & "Serial Number: " & objBIOS.SerialNumber & vbCrLf
report = report & "SMBIOS Version: " & objBIOS.SMBIOSBIOSVersion & vbCrLf
report = report & "SMBIOS Major Version: " & objBIOS.SMBIOSMajorVersion & vbCrLf
report = report & "SMBIOS Minor Version: " & objBIOS.SMBIOSMinorVersion & vbCrLf
report = report & "SMBIOS Present: " & objBIOS.SMBIOSPresent & vbCrLf
report = report & "Status: " & objBIOS.Status & vbCrLf
report = report & "Version: " & objBIOS.Version & vbCrLf
For i = 0 to Ubound(objBIOS.BiosCharacteristics)

Next
Next

report = report & vbCrLf & "******************************************" & vbCrLf
report = report & "Video Information" & vbCrLf & "******************************************" & vbCrLf & vbCrLf
Set colItems = objWMIService.ExecQuery( "Select * from Win32_VideoController", , 48 )
' Display error number and description if applicable
If Err Then ShowError
' Prepare display of results
For Each objItem in colItems
report = report & " Name: " & objItem.Name & vbCrLf
report = report & " Description: " & objItem.Description & vbCrLf
report = report & " Video Processor: " & objItem.VideoProcessor & vbCrLf
report = report & " Adapter RAM: " & Int( ( objItem.AdapterRAM + 524288 ) / 1048576 ) & " MB" & vbCrLf
report = report & " Video Mode Description: " & objItem.VideoModeDescription & vbCrLf & vbCrLf
Next

report = report & vbCrLf & "******************************************" & vbCrLf
report = report & "Disk Drive Information" & vbCrLf & "******************************************" & vbCrLf & vbCrLf

Set colItems = objWMIService.ExecQuery( "Select * from Win32_DiskDrive", , 48 )
' Display error number and description if applicable
If Err Then ShowError
' Prepare display of results

For Each objItem in colItems

report = report & " Manufacturer: " & objItem.Manufacturer & vbCrLf
report = report & " Model: " & objItem.Model & vbCrLf
report = report & " Size: " & Int( ( objItem.Size + 536870912 ) / 1073741824 ) & " GB" & vbCrLf & vbCrLf

Next

oReg.EnumKey HKEY_LOCAL_MACHINE, UnInstPath, arrSubKeys
software = software & vbCrLf & "******************************************" & vbCrLf
software = software & "Installed Software" & vbCrLf & "******************************************" & vbCrLf & vbCrLf
For Each subkey In arrSubKeys
'MsgBox subkey
If Left (subkey, 1) <> "{" Then
software = software & subkey & vbCrLf
End If
Next


Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile ("hardwareinventory.txt", ForWriting)
ts.write report
ts.write software
ts.close



'MsgBox Report
Wscript.Echo "Done"
--------------------------------------------------------

That's what it looks like now and works great. Needs cleaned up a bit and such but I'll get to that later cause I'm not quite done.

I am still trying to add the command line argument so I can choose computers on my domain. Like I've said, I'm very new to scripting so I'm not quite sure how to integrate yours into it. It didn't seem to do anything. But I remembered I had a script that I did a month ago for processes. So I took the argument part of it and added it in:

---------------------------------------------
If WScript.Arguments.Count = 0 Then
WScript.Echo("You must enter a computer name")
Else
Set objIdDictionary = CreateObject("Scripting.Dictionary")
strComputer = WScript.Arguments(0)
colComputers = split(strComputer, ",")
---------------------------------------------------------

And I added the End If at the end of the script for it. Now, it works to an extent. It will ask me for a computer name to enter. I can pull information from machine2 on my domain. However, I can't properly pull information with a string like; machine1,machine2. If I wanted both of them at one time, I just end up with a mostly blank text file (well blank in the spots where the retrieved data should be, except the installed software). Which is my next point.

I need to also somehow figure out how to incorporate the installed software properly. It will only pull the list of installed software from the local machine. Not a machine on the domain that I choose. I need to tweak that somehow. Maybe I need to do something with LDAP?

I can see a lot of people looking at this like a mess lol. But hey I'm trying and it is kind of fun. I just can't figure it all out so if anyone has any ideas.
 
Functions. Put each chuck of data retrieval code in it's own function and then loop through the computers. Remember to define your objects and variable in the main scope (outside the functions) to use them globally. Define them within the functions scope to pertain ONLY to the functions code.

Code:
for each strComputer in colComputers
  getBIOS
  getSoftware
  getVideo
  write data to output file
next

Also, notice that strComputer is defined at the beginning of the script (strComputer = env.Item("Computername")) Take that line out and add the above code. It's the only code that should not be a function. This makes it easy to read, understand and troubleshoot.

As for command line arguments, your code works fine if you use comma separated arguments. When you incorporate a space, you now have 2 arguments.

Examples:
audit.vbs finance,c:\finance.txt,1
Only one argument "finance,c:\finance.txt,1"

audit.vbs finance c:\finance.txt 1
Three arguments "finance", "c:\finance.txt" and "1"

Use this code to learn how arguments work by passing it random data from the cmdline.

cmdlineArgs.vbs
Code:
set objArgs = wscript.Arguments

for i = 0 to objArgs.count
   msgbox i & ": " & objArgs(i)
next

try passing it things like:
cmdlineArgs.vbs pinap ple up_side "down cake"
arg1: pinap
arg2: ple
arg3: up_side
arg4: down cake

-Geates
 
Thanks again for the quick reply,

I've been searching around and trying to understand it all. I'm a bit further, but not totally complete. If I add in the line of code that you put up:

"for each strComputer in colComputers
getBIOS
getSoftware
getVideo
write data to output file
next"

I'll get an error message stating "expected end of statement" on the line that says write data to output file. Haven't figured out the issue just yet.

Also, I learned something about the installed software. It will only pull installed software from the local machine. Even if it grabs all the other information from another machine on my domain, the installed software is always from the local machine.

So I read that this line "".\root\default:StdRegProv")"
is what does it.

It is because of that period in front of \root which says to grab it from the local. If I remove the period and add in the machine name manually "machine2\root" it will grab installed software from machine2. Which is nice, but is there anything I can put in there that will have it grab from the machine I choose at the command line? Instead of having to manually put the machine name in there?

Thanks for all the help!
 
write data to output file" isn't code. I'm implying that you create a function that writes data to an output file.

Yes, the period represents the local machine. If you want to use an argument, use the code above. Let me try and explain it better.

Code:
set objArgs = wscript.Arguments

'loop through each argument and re-establish the registry object
for i = 0 to objArgs.count
  strComputer = objArgs(i)
  set objReg = GetObject("winmgmts:impersonationLevel=impersonate}!\\[red]" & strComputer & "[/red]\root\default:StdRegProv")
  [blue]do stuff[/blue]
next

So a cmdline like "audit.vbs machine1 machine9 machine4" would [blue]do stuff[/blue] to each argument. machine1 would be first. machine9 second and machine4 third.

-Geates
 
Hi Geates,

I was just coming on here to post that I figured out the local machine issue this morning. It's just as you said.

I changed
"Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
".\root\default:StdRegProv")"

to

"Set oReg=GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")"

and now it's starting to roll after moving my argument command higher as well. The script is now nearly where I want it. I can pull all the information I need from each machine. The only other thing I'm looking into is the argument line of "script.vbs machine1 machine2". I'm still having issues with combining them. However, if I do "script.vbs machine1" or "script.vbs machine2" separately, it will output each machine fine. I can be pretty happy with just that. Considering I need to have this finished by this evening.

I appreciate all your help and with what you recently posted I'm going to look into the argument line more. If I still can't get it, it is pretty good as it currently stands.
 
the code block in my previous post will accomplish what you want. If it doesn't, post your script and I'll look at it.

-Geates
 
Hey Geates,

Okay, If you want to take a look if you have time, here's the working script without the additions above but in a near fully working mode besides being able to have it spit out separate text files for each machine:

-----------------------------------------------------------
On Error Resume Next



Dim strComputer
Dim oShell
Dim colComputers
Dim env
Dim oReg
Dim objIdDictionary
Dim report
Dim objWMIService
Dim colItems
Dim objItem
Dim colSettings
Dim objProcessor
Dim objBIOS
Dim text


Set oShell = CreateObject("wscript.Shell")
Set env = oShell.environment("Process")

strComputer = WScript.Arguments(0)
If WScript.Arguments.Count = 0 Then ' using an if then command for arguments
WScript.Echo("You must enter a computer name") ' if the argument is 0 then we will get the message to enter a computer name
Else ' if we enter a name then else will kick in


Const HKEY_LOCAL_MACHINE = &H80000002
Const UnInstPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
Set oReg=GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")




report = strComputer & " Computer Inventory" & vbCrLf & "------------------------------------------" & vbCrLf & vbCrLf
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)

report = report & vbCrLf & "------------------------------------------" & vbCrLf
report = report & "Operating System" & vbCrLf & "------------------------------------------" & vbCrLf & vbCrLf
For Each objItem in colItems
report = report & "Caption: " & objItem.Caption & vbCrLf
report = report & "Description: " & objItem.Description & vbCrLf
report = report & "EncryptionLevel: " & objItem.EncryptionLevel & vbCrLf
report = report & "InstallDate: " & objItem.InstallDate & vbCrLf
report = report & "Manufacturer: " & objItem.Manufacturer & vbCrLf
report = report & "MaxNumberOfProcesses: " & objItem.MaxNumberOfProcesses & vbCrLf
report = report & "Name: " & objItem.Name & vbCrLf
report = report & "Organization: " & objItem.Organization & vbCrLf
report = report & "OSProductSuite: " & objItem.OSProductSuite & vbCrLf
report = report & "RegisteredUser: " & objItem.RegisteredUser & vbCrLf
report = report & "SerialNumber: " & objItem.SerialNumber & vbCrLf
report = report & "ServicePackMajorVersion: " & objItem.ServicePackMajorVersion
report = report & "ServicePackMinorVersion: " & objItem.ServicePackMinorVersion & vbCrLf
report = report & "Version: " & objItem.Version & vbCrLf
report = report & "WindowsDirectory: " & objItem.WindowsDirectory & vbCrLf
Next



Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
report = report & vbCrLf & "------------------------------------------" & vbCrLf
report = report & "RAM Information" & vbCrLf & "------------------------------------------" & vbCrLf & vbCrLf
For Each objComputer in colSettings
'report = report & objComputer.Name & vbcrlf
report = report & objComputer.TotalPhysicalMemory /1024\1024+1 & "MB Total memory" & vbcrlf
Next

Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_Processor" , , 48 )
report = report & vbCrLf & "------------------------------------------" & vbCrLf
report = report & "Processor" & vbCrLf & "------------------------------------------" & vbCrLf & vbCrLf
For Each objProcessor in colSettings

report = report & "Name: " & objProcessor.Name & vbCrLf
report = report & "Manufacturer: " & objProcessor.Manufacturer & vbCrLf
report = report & "Description: " & objProcessor.Description & vbCrLf
report = report & "Current Clock Speed: " & objProcessor.CurrentClockSpeed & " MHz" & vbCrLf & vbCrLf
Next


report = report & vbCrLf & "------------------------------------------" & vbCrLf
report = report & "BIOS Information" & vbCrLf & "------------------------------------------" & vbCrLf & vbCrLf
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_BIOS")
For each objBIOS in colSettings
report = report & "Build Number: " & objBIOS.BuildNumber & vbCrLf
report = report & "Current Language: " & objBIOS.CurrentLanguage & vbCrLf
report = report & "Installable Languages: " & objBIOS.InstallableLanguages & vbCrLf
report = report & "Manufacturer: " & objBIOS.Manufacturer & vbCrLf
report = report & "Name: " & objBIOS.Name & vbCrLf
report = report & "Primary BIOS: " & objBIOS.PrimaryBIOS & vbCrLf
report = report & "Release Date: " & objBIOS.ReleaseDate & vbCrLf
report = report & "Serial Number: " & objBIOS.SerialNumber & vbCrLf
report = report & "SMBIOS Version: " & objBIOS.SMBIOSBIOSVersion & vbCrLf
report = report & "SMBIOS Major Version: " & objBIOS.SMBIOSMajorVersion & vbCrLf
report = report & "SMBIOS Minor Version: " & objBIOS.SMBIOSMinorVersion & vbCrLf
report = report & "SMBIOS Present: " & objBIOS.SMBIOSPresent & vbCrLf
report = report & "Status: " & objBIOS.Status & vbCrLf
report = report & "Version: " & objBIOS.Version & vbCrLf



Next

report = report & vbCrLf & "------------------------------------------" & vbCrLf
report = report & "Video Information" & vbCrLf & "------------------------------------------" & vbCrLf & vbCrLf
Set colSettings = objWMIService.ExecQuery( "Select * from Win32_VideoController", , 48 )
' Display error number and description if applicable
If Err Then ShowError
' Prepare display of results
For Each objItem in colSettings
report = report & " Name: " & objItem.Name & vbCrLf
report = report & " Description: " & objItem.Description & vbCrLf
report = report & " Video Processor: " & objItem.VideoProcessor & vbCrLf
report = report & " Adapter RAM: " & Int( ( objItem.AdapterRAM + 524288 ) / 1048576 ) & " MB" & vbCrLf
report = report & " Video Mode Description: " & objItem.VideoModeDescription & vbCrLf & vbCrLf
Next

report = report & vbCrLf & "------------------------------------------" & vbCrLf
report = report & "Hard Drive Information" & vbCrLf & "------------------------------------------" & vbCrLf & vbCrLf

Set colSettings = objWMIService.ExecQuery( "Select * from Win32_DiskDrive", , 48 )
' Display error number and description if applicable
If Err Then ShowError
' Prepare display of results

For Each objItem in colSettings

report = report & " Manufacturer: " & objItem.Manufacturer & vbCrLf
report = report & " Model: " & objItem.Model & vbCrLf
report = report & " Size: " & Int( ( objItem.Size + 536870912 ) / 1073741824 ) & " GB" & vbCrLf & vbCrLf

Next

oReg.EnumKey HKEY_LOCAL_MACHINE, UnInstPath, arrSubKeys
software = software & vbCrLf & "------------------------------------------" & vbCrLf
software = software & "Installed Software" & vbCrLf & "------------------------------------------" & vbCrLf & vbCrLf
For Each subkey In arrSubKeys
'MsgBox subkey
If Left (subkey, 1) <> "{" Then
software = software & subkey & vbCrLf
End If
Next


Set fso = CreateObject("Scripting.FileSystemObject")
Set text = fso.CreateTextFile (strComputer & ".txt", ForWriting)
text.write report
text.write software
text.close
End If

'MsgBox Report
Wscript.Echo "I have finished retrieving the information"
----------------------------------------------------------

With that I am able to do something like, script.vbs machine1 (and it will grab all the info and put it into a text file). and if I put machine2, it will grab all the info from that machine on the domain. But if I put script.vbs machine1 machine2 it won't.

So I was tinkering with it with what you posted above and the other advice. I tried a line of code like this, I know it will look messy and very wrong, but I was trying anyway:

--------------------------------------------------------
strComputer = WScript.Arguments(0)
If WScript.Arguments.Count = 0 Then
WScript.Echo("You must enter a computer name") '
Else

set objArgs = wscript.Arguments

'loop through each argument and re-establish the registry object
for i = 0 to objArgs.count
strComputer = objArgs(i)
For Each strComputer in colComputers
Set fso = CreateObject("Scripting.FileSystemObject")
Set text = fso.CreateTextFile (strComputer & ".txt", ForWriting)
text.write report
text.write software
text.close
next
next
------------------------------------------------------

Okay, if I add that in then I can type, script.vbs machine1 machine2. and it will spit out two text files with the names, but no information in them. I messed around with it a bit more and I was able to get it to spit information at one of them. But now I'm back to 0.

I know it isn't right obviously. But that is what I was trying to all take in from the previous comments. I feel that I'm so close on it.
 
Again, you need to put chunks of code into functions to make it easier to read and understand. You have three MAJOR issues.

1. At the top of your script, you are statically assigning "strComputer" to wscript.Arguments(0). This means it can be nothing else.

2. Because of #1, your are only getting details of one computer.

3. The last part of your script loops through each argument and assigns it to "strComputer." The very next statment is looping through colComputer (which hasn't been defined, thus empty) and re-assigning an empty value to the same "strComputer." Then it writes the same details to an empty filename. You need to encapsulate your entire code in a single for loop.

It should look like this:

Code:
'Define your variables and object
set objArgs = wscript.arguments
set objFSO  = CreateObject("Scripting.FileSystemObject")

if (objArgs.count = 0) then
   msgbox "You must pass an argument"
end if

for i = 0 to objArgs.count - 1
   strComputer = objArgs(i)
   [blue] do all your code [/blue]
   set objOutput = objFSO.OpenTextFile (strComputer & ".txt", 2, true, 0)
   objOutput.write report
   objOutput.close
next i


Also, when you post, try and put your code between
Code:
 tags to preserve formatting.  Just typing code outside the tags makes it really troublesome to copy/paste/format.

-Geates
 
parasomia: I would also remove the first line "On Error Resume Next
 
If you have some time you can try setup Open-Audit

You may need to download WAMP to make the learning curve of Apache, MySQL, PHP easier.


MCITP:EA/SA, MCSE, MCSA, MCDBA, MCTS, MCP+I, MCP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top