Login Script: Inventory Collection for domain computers

Here is the another script to collect the asset inventory of domain Computers over network. it will collect the Hardware and Software information of the Windows PC/Laptops which are logging into domain.


This is the easy to collect asset inventory of your networked Windows PC/Laptops. 

It will create two files for each computer: 





1 A file contains hardware details (Serial no, Model No, User, etc..)
2. Another file contains list of installed softwares on the computers


You can use txtcollector tool to merge all these files into one. you can easily import into excel and customize your report.


Place this script as your login script. or place this script in network drive and call it from your master login script.
Create a new group policy for this and assign to entire domain.






Note: you need create a network share to place the inventory files with everyone and domain users writer permissions


If you have questions, Please comment...I will get back to you... 


Copy the script below..
'-----------------------------------------------------------------------




Option Explicit
Wscript.Timeout = 60


' -- DECLARATIONS ----------------


Dim sComputer
Dim sHardKeys
Dim sCompName, sCompSN, sNetMAC, sOSUsername
Dim sLocation
Dim bInteractive
Dim sContent, sFileName, sOutputPath
Dim i, iArgs
Dim sTitle
Dim sFieldSeparator




' -- DEFAULT VALUES -----------------


sFieldSeparator = ";"
bInteractive = true
sLocation = ""
sComputer = ""
sOutputPath = ""




sComputer = "."


sOutputPath = "\\YOUR_NETWORK_SHARED_DRIVE\Asset Tracking"


sLocation = "empty location"






' -- HARDWARE INVENTORY --------------


sContent = GetHardwareInventory(sComputer, sFieldSeparator)


' Save inventory in file within selected path
' Format : ComputerName_SerialNumber_MACAddress_YYYYMM_Hardware.csv


sFileName = sOutputPath & "\" & Replace(sOSUsername, "YOURDOMAIN\", "") & "__" & sCompSN & "__" & Replace(sNetMAC, ":", "") & "_Hardware.txt"


If WriteFile(sContent, sFileName) Then


End If


' -- SOFTWARE INVENTORY --------------


sHardKeys = sCompSN & sFieldSeparator & _
sCompName & sFieldSeparator & _ 
sOSUsername & sFieldSeparator & _
sNetMAC & sFieldSeparator


sContent = GetSoftwareInventory(sComputer, sFieldSeparator, sHardKeys)


' Save inventory in file within selected path
' Format : ComputerName_SerialNumber_MACAddress_YYYYMM_Software.csv






sFileName = sOutputPath & "\" & Replace(sOSUsername, "YOURDOMAIN\", "") & "__" & sCompSN & "__" & Replace(sNetMAC, ":", "") &  "_Software.txt"




If WriteFile(sContent, sFileName) Then


End If


' -- END OF SCRIPT ----------------
Wscript.quit
' -- END OF SCRIPT ----------------










'======================
' GetWMIValue : get information with a WMI query on a local or remote computer
'
' Arguments :
' * sComp Computer to connect to
' * sTable WMI table to query
' * sKey Information to get
' * sWhere WHERE clause of the query
'
' Global variable
' * objWMIService This object is global for maximum performance
'======================
Dim oWMIService
Function GetWMIValue(sComp, sTable, sKey, sWhere)
Dim oColItems, oItem


' We disable error handling...
' ...then we check if connection is already established...
' ...and we re-enable error handling
On Error Resume Next
If isEmpty(oWMIService) Then
Set oWMIService = GetObject("winmgmts://" & sComp & "/root/cimv2")
End If
On Error Goto 0


' If connection isn't established now...
' ...it's because we can't connect to the remote computer
if isEmpty(oWMIService) then
ShowMesg "L'ordinateur dont le nom ou l'IP est '" & sComp & _
"' n'est pas joignable."
Wscript.quit
End If


' If there is a WHERE clause, add it...
' ...and do the query
if sWhere = "" Then
Set oColItems = oWMIService.ExecQuery("Select * from " & sTable,,48)
Else
Set oColItems = oWMIService.ExecQuery("Select * from " & sTable & _
" Where " & sWhere,,48)
End If


' Get the returned value
For Each oItem in oColItems
GetWMIValue = oItem.Properties_(sKey)
Next


' We clean objects created before...
' ...except oWMIService (for later use)
Set oColItems = Nothing
Set oItem = Nothing
End Function




'======================
' WriteFile : write information to a file
'
' Arguments :
' * sData Data to write
' * sFilename Name of the file to write to
'======================
Function WriteFile(sData, sFilename)
Dim oFSO, oFile, bWrite
bWrite = True


' We create FileSystemObject...
' ...then we disable error handling...
' ...try to open the file in write mode...
' ...and we re-enable error handling
Set oFSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set oFile = oFSO.OpenTextFile(sFilename, 2, True)
' Possibly need a prompt to close the file and one recursion attempt
If Err = 70 Then
ShowMesg "Impossible d'écrire dans le fichier " & sFilename
bWrite = False
ElseIf Err Then
ShowMesg err & vbcrlf & err.description
bWrite = False
End If
On Error GoTo 0


If bWrite Then
oFile.WriteLine(sData)
oFile.Close
End If


' We clean objects created before
Set oFSO = Nothing
Set oFile = Nothing


' We return the overall status
WriteFile = bWrite
End Function




'======================
' BubbleSort : cheap bubble sort function
'
' Arguments :
' * sData Data to sort
'======================
Function BubbleSort(sData)
Dim aData, i, j, sTemp


' We explode data in an array
aData = Split(sData, vbCrLf)


' We sort data in the array
For i = UBound(aData) - 1 To 0 Step -1
For j = 0 to i - 1
If LCase(aData(j)) > LCase(aData(j+1)) Then
sTemp = aData(j + 1)
aData(j + 1) = aData(j)
aData(j) = sTemp
End if
Next
Next


' We implode array and return data
BubbleSort = Join(aData, vbCrLf)
End Function




'======================
' GetHardwareInventory : hardware inventory build with WMI requests.
' (use GetWMIValue function)
'
' Arguments :
' * sComp Computer to inventory
' * sSep separator used to format output
'
' Global variables
' * sCompName used in filename
' * sCompSN used in filename
' * sNetMAC used in filename
'======================
Function GetHardwareInventory(sComp, sSep)
'Dim sCompName, sCompSN
Dim sCompMfr, sCompModel
'Dim sWrtyBeginDate, sWrtyExpirationDate
Dim sBIOSVersion, iRAM, sCPU, iCPUSpeed
Dim sOS, sOSSP, sMachinetype
'Dim sMonitorMfr, sMonitorModel, sMonitorSN, strMonitoMfrDate
'Dim sVideoDesc, sVideoMode, intVideoRAM
Dim sNetCard, sNetIP
'Dim sNetMAC


' -- Computer Informations -------
sCompName = GetWMIValue(sComputer, "Win32_ComputerSystem", "Name", "")
sCompMfr = GetWMIValue(sComputer, "Win32_ComputerSystem", _
"Manufacturer", "")
sCompModel = GetWMIValue(sComputer, "Win32_ComputerSystem", "Model", "")
sCompSN = GetWMIValue(sComputer, "Win32_BIOS", "SerialNumber", "")
' -- Warranty Informations (not used yet) ----
' -- Misc. Hardware Informations ----
sBIOSVersion = GetWMIValue(sComputer, "Win32_BIOS", "Version", "")
iRAM = Clng(GetWMIValue(sComputer, "Win32_ComputerSystem", _
"TotalPhysicalMemory", "") / (1024*1024))
sCPU = Trim(GetWMIValue(sComputer, "Win32_Processor", "Name", ""))
iCPUSpeed = Clng(GetWMIValue(sComputer, "Win32_Processor", _
"MaxClockSpeed", ""))
' -- OS Informations -------
sOS = GetWMIValue(sComputer, "Win32_OperatingSystem", "Caption", "")
sOSSP = GetWMIValue(sComputer, "Win32_OperatingSystem", _
"CSDVersion", "")
sOSUsername = GetWMIValue(sComputer, "Win32_ComputerSystem", "UserName", "")
' -- Video Card Informations -----
'sVideoDesc = GetWMIValue(sComputer, "Win32_VideoController", _
' "Description", "")
'sVideoMode = GetWMIValue(sComputer, "Win32_VideoController", _
' "VideoModeDescription", "")
'intVideoRAM = Clng(GetWMIValue(sComputer, "Win32_VideoController", _
' "AdapterRAM", "") / (1024*1024))
' -- Network Informations --------
sNetCard = GetWMIValue(sComputer, "Win32_NetworkAdapterConfiguration", _
"ServiceName", "IPEnabled=TRUE")
sNetIP = GetWMIValue(sComputer, "Win32_NetworkAdapterConfiguration", _
"IPAddress", "IPEnabled=TRUE")(0)
sNetMAC = GetWMIValue(sComputer, "Win32_NetworkAdapterConfiguration", _
"MACAddress", "IPEnabled=TRUE")
sMachinetype = GetWMIValue(sComputer, "Win32_ComputerSystemProduct", "Version", "")


' Format output string with a separator given on argument
GetHardwareInventory = sOSUsername & sSep & _
sCompName & sSep & _
sCompMfr & sSep & _
sMachinetype & sSep & _
sCompModel & sSep & _
sCompSN & sSep & _
sOS & sSep & _
sOSSP & sSep & _
sCPU & sSep & _
iRAM & sSep & _
sNetIP & sSep & _
sNetMAC & sSep & _
sNetCard & sSep & _
sBIOSVersion 


End Function




'======================
' GetSoftwareInventory : Software inventory build with WMI requests.
' (use BubbleSort function)
'
' Arguments :
' * sComp Computer to inventory
' * sSep Separator used to format output
' * sPrefix Prefix to add on each line
'======================
Function GetSoftwareInventory(sComp, sSep, sPrefix)
Dim cnt, oReg, sBaseKey, iRC, aSubKeys
Dim sKey, sValue, sTmp, sVersion, sDateValue, sYr, sMth, sDay
Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE


Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
sComputer & "/root/default:StdRegProv")
sBaseKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
iRC = oReg.EnumKey(HKLM, sBaseKey, aSubKeys)


For Each sKey In aSubKeys
iRC = oReg.GetStringValue(HKLM, sBaseKey & sKey, "DisplayName", sValue)
If iRC <> 0 Then
oReg.GetStringValue HKLM, sBaseKey & sKey, "QuietDisplayName", sValue
End If
If sValue <> "" Then
iRC = oReg.GetStringValue(HKLM, sBaseKey & sKey, _
"DisplayVersion", sVersion)
If sVersion <> "" Then
sValue = sValue & sSep & sVersion
Else
sValue = sValue & sSep
End If
iRC = oReg.GetStringValue(HKLM, sBaseKey & sKey, _
"InstallDate", sDateValue)
If sDateValue <> "" Then
sYr = Left(sDateValue, 4)
sMth = Mid(sDateValue, 5, 2)
sDay = Right(sDateValue, 2)
'some Registry entries have improper date format
On Error Resume Next
sDateValue = DateSerial(sYr, sMth, sDay)
On Error GoTo 0
If sdateValue <> "" Then
sValue = sValue & sSep & sDateValue
End If
End If
sTmp = sTmp &  sPrefix & sValue & vbcrlf
cnt = cnt + 1
End If
Next


GetSoftwareInventory = BubbleSort(sTmp)
End Function

Share this

Related Posts

Previous
Next Post »

2 comments

Write comments
Anonymous
January 24, 2015 at 8:53 AM delete

Buenas noches!

Me gustaría usar este script pero no me funciona.

me puede ayudar!

Gracias!!

Richard
rabogado@hotmail.com

Reply
avatar
January 6, 2017 at 11:23 AM delete

hi, i tried to save in my local computer but it didnt work, can u help me

Reply
avatar

What do you think about this Article? Add your Opinion..! EmoticonEmoticon