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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with pc inventory script

Status
Not open for further replies.

garymass

IS-IT--Management
Oct 29, 2001
57
US
I'm a newbie with this, so please excuse my ignorance in advance :)

I found this script on the web, but cannot seem to make it work. I keep getting error on line 56 col 7 stating that "remote server machine does not exist", but I dont know enough yet to find the actual error. is it referring to the server I am trying to send the output file to?

line 56 col 7 has:
Set objWMIService = GetObject("winmgmts:\\" & _
sComputer & "\root\cimv2")


here is the entire script:

'get domain name
Dim sDomain
sDomain = InputBox("Enter domain to inventory")

'connect to domain and retrieve
'a list of member objects
Dim oDomain
Set oDomain = GetObject("WinNT://" & sDomain)

'get the filesystemobject
Dim oFSO
Set oFSO = CreateObject("Scripting.FileSystemObject")

'open an output file
Dim oOutput
Set oOutput = oFSO.CreateTextFile("\\ourserver\public\output.txt")

'run through the objects
Dim oObject, sComputerName, sDetails
For Each oObject In oDomain

'is this object a computer?
If oObject.Class = "Computer" Then

'yes - get computer name
sComputerName = oObject.Name

'get OS info
sDetails = GetOSInfo(sComputerName)

'write info to the file
oOutput.Write sDetails

End If
Next
'close the output file
oOutput.Close

'release objects
Set oOutput = Nothing
Set oFSO = Nothing
Set oObject = nothing
Set oDomain = Nothing

'display completion message
WScript.Echo "Output saved to \\ourserver\public\output.txt"

Function GetOSInfo(sComputer)

'declare variables
Dim objWMIService
Dim colItems
Dim strOutput

'get WMI service
Set objWMIService = GetObject("winmgmts:\\" & _
sComputer & "\root\cimv2")

'get item collection
Set colItems = objWMIService.ExecQuery( _
"Select * from Win32_OperatingSystem",,48)

'init output string
strOutput = String(70,"-") & vbcrlf
strOutput = strOutput & sComputer & vbcrlf

'append info to output string
For Each objItem in colItems
strOutput = strOutput & "BuildNumber: " & _
objItem.BuildNumber & vbCrLf
strOutput = strOutput & "BuildType: " & _
objItem.BuildType & vbCrLf
strOutput = strOutput & "Caption: " & _
objItem.Caption & vbCrLf
strOutput = strOutput & "EncryptionLevel: " & _
objItem.EncryptionLevel & vbCrLf
strOutput = strOutput & "InstallDate: " & _
objItem.InstallDate & vbCrLf
strOutput = strOutput & "Manufacturer: " & _
objItem.Manufacturer & vbCrLf
strOutput = strOutput & "MaxNumberOfProcesses: " & _
objItem.MaxNumberOfProcesses & vbCrLf
strOutput = strOutput & "MaxProcessMemorySize: " & _
objItem.MaxProcessMemorySize & vbCrLf
strOutput = strOutput & "Name: " & _
objItem.Name & vbCrLf
strOutput = strOutput & _
"NumberOfLicensedUsers: " & _
objItem.NumberOfLicensedUsers & vbCrLf
strOutput = strOutput & "NumberOfProcesses: " & _
objItem.NumberOfProcesses & vbCrLf
strOutput = strOutput & "NumberOfUsers: " & _
objItem.NumberOfUsers & vbCrLf
strOutput = strOutput & "OSProductSuite: " & _
objItem.OSProductSuite & vbCrLf
strOutput = strOutput & "OSType: " & _
objItem.OSType & vbCrLf
strOutput = strOutput & "OtherTypeDescription: " & _
objItem.OtherTypeDescription & vbCrLf
strOutput = strOutput & "Primary: " & _
objItem.Primary & vbCrLf
strOutput = strOutput & "ProductType: " & _
objItem.ProductType & vbCrLf
strOutput = strOutput & "RegisteredUser: " & _
objItem.RegisteredUser & vbCrLf
strOutput = strOutput & "SerialNumber: " & _
objItem.SerialNumber & vbCrLf
strOutput = strOutput & _
"ServicePackMajorVersion: " & _
objItem.ServicePackMajorVersion & vbCrLf
strOutput = strOutput & _
"ServicePackMinorVersion: " & _
objItem.ServicePackMinorVersion & vbCrLf
strOutput = strOutput & "Version: " & _
objItem.Version & vbCrLf
strOutput = strOutput & "WindowsDirectory: " & _
objItem.WindowsDirectory & vbCrLf
Next

'return results
GetOSInfo = strOutput

End Function
 
You might get that error if the computer is turned off or unreachable. Before you call your function you may want to check if the computer is reachable before attempting to retrieve any info.

One way would be to do a simple ping which you should be able to find examples of here.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top