CommCatz
asked on
Add WMI Query to Existing VBscript
We have an existing logon Vbscript that writes information to each computer's and user's description field in Active Directory and so far it works great. We have found the need to add a wmi query of each computer's serial number to the script's output as well.
Here is the current code that we are using:
''POPULATES AD WITH USER LOGON INFO IN DESCRIPTION FIELD
Set objSysInfo = CreateObject("ADSystemInfo ")
unEscapedUserName = Replace(objSysInfo.UserNam e, "/", "\/")
Set objUser = GetObject("LDAP://" & unEscapedUserName)
Set objUser = GetObject("LDAP://" & Replace(objSysInfo.UserNam e, "/", "\/"))
Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName)
strMessage1 = " Authenticated on: " & objComputer.CN & " at " & Now & ". MAC: " & MACAddresses(".")
strMessage2 = " MAC: " & MACAddresses(".") & "." & " Authenticated by: " & objUser.CN & " at " & Now & "."
objUser.Description = strMessage1
objUser.SetInfo
objComputer.Description = strMessage2
objComputer.SetInfo
function MACAddresses(strComputer)
dim objWMI, colItems, objItem
dim strMac
strMac=""
Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMI.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfig uration where IPEnabled=TRUE",,48)
For Each objItem in colItems
if objItem.MACAddress<>"" then strMac=strMac & objItem.MACAddress & vbCrLf
Next
MACAddresses = strMac
end function
I found the following snippet that queries and returns what we need to add; however it obviously just returns screen output.
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("S elect * from Win32_BaseBoard")
For Each objItem in colItems
For Each strOption in objItem.ConfigOptions
Next
Wscript.Echo "Serial Number: " & objItem.SerialNumber
Next
How can we add the above wmi query to write the Serial Number to both of the following output lines (in our working logon script)?
strMessage1 = " Authenticated on: " & objComputer.CN & " at " & Now & ". MAC: " & MACAddresses(".")
strMessage2 = " MAC: " & MACAddresses(".") & "." & " Authenticated by: " & objUser.CN & " at " & Now & "."
I'd like the Serial Number query to be at the end of the strMessage1 line and at the beginning of the strMessage2 line.
Is this possible?
Here is the current code that we are using:
''POPULATES AD WITH USER LOGON INFO IN DESCRIPTION FIELD
Set objSysInfo = CreateObject("ADSystemInfo
unEscapedUserName = Replace(objSysInfo.UserNam
Set objUser = GetObject("LDAP://" & unEscapedUserName)
Set objUser = GetObject("LDAP://" & Replace(objSysInfo.UserNam
Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName)
strMessage1 = " Authenticated on: " & objComputer.CN & " at " & Now & ". MAC: " & MACAddresses(".")
strMessage2 = " MAC: " & MACAddresses(".") & "." & " Authenticated by: " & objUser.CN & " at " & Now & "."
objUser.Description = strMessage1
objUser.SetInfo
objComputer.Description = strMessage2
objComputer.SetInfo
function MACAddresses(strComputer)
dim objWMI, colItems, objItem
dim strMac
strMac=""
Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMI.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfig
For Each objItem in colItems
if objItem.MACAddress<>"" then strMac=strMac & objItem.MACAddress & vbCrLf
Next
MACAddresses = strMac
end function
I found the following snippet that queries and returns what we need to add; however it obviously just returns screen output.
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("S
For Each objItem in colItems
For Each strOption in objItem.ConfigOptions
Next
Wscript.Echo "Serial Number: " & objItem.SerialNumber
Next
How can we add the above wmi query to write the Serial Number to both of the following output lines (in our working logon script)?
strMessage1 = " Authenticated on: " & objComputer.CN & " at " & Now & ". MAC: " & MACAddresses(".")
strMessage2 = " MAC: " & MACAddresses(".") & "." & " Authenticated by: " & objUser.CN & " at " & Now & "."
I'd like the Serial Number query to be at the end of the strMessage1 line and at the beginning of the strMessage2 line.
Is this possible?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER