vbscript based computer inventory scripts

strComputer = “.” Set objWMIService = GetObject(“winmgmts:” _     & “{impersonationLevel=impersonate}!\\” _     & strComputer & “\root\cimv2”) Set colOperatingSystems = objWMIService.ExecQuery _     (“Select * from Win32_OperatingSystem”) For Each objOperatingSystem in colOperatingSystems     Wscript.Echo objOperatingSystem.Caption & _     ”  ” & objOperatingSystem.Version Next

strComputer = “.” Set objWMIService = GetObject( _     “winmgmts:\\” & strComputer & “\root\cimv2”) Set IPConfigSet = objWMIService.ExecQuery _     (“Select IPAddress from Win32_NetworkAdapterConfiguration” _         & ” where IPEnabled=TRUE”)   For Each IPConfig in IPConfigSet     If Not IsNull(IPConfig.IPAddress) Then         For i=LBound(IPConfig.IPAddress) _         to UBound(IPConfig.IPAddress)             WScript.Echo IPConfig.IPAddress(i)         Next     End If Next

Get active directory role with vbscript

sComputer = “.” WScript.Echo DomainRole(sComputer)

Function DomainRole(sNode) Set oWMI = GetObject(“winmgmts:” _ & “{impersonationLevel=impersonate}!\\” & sNode & “\root\cimv2”) Set colComputer = oWMI.ExecQuery _ (“Select DomainRole from Win32_ComputerSystem”) For Each oComputer in colComputer iDR = oComputer.DomainRole Next

Select Case iDR Case 0 DomainRole = “Standalone Workstation” Case 1 DomainRole = “Member Workstation” Case 2 DomainRole = “Standalone Server” Case 3 DomainRole = “Member Server” Case 4 DomainRole = “Backup Domain Controller” Case 5 DomainRole = “Primary Domain Controller” Case Else DomainRole = “Unknown” End Select

End Function

vbscript to copy file to multiple computers from list

Const ForReading = 1
Const OverwriteExisting = TRUE

Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set objFile = objFSO.OpenTextFile(“C:\Computers.txt”)

Do Until objFile.AtEndOfStream
strComputer = objFile.ReadLine
strRemoteFile = “\\” & strComputer & “\C$\example.vbs”
objFSO.CopyFile “C:\example.vbs”, strRemoteFile, OverwriteExisting
Loop

vbscript to find Symantec Endpoint or Antivirus Version, .bat example as well

WMI needed ->

strComputer = “.”

Set objWMIService = GetObject(“winmgmts:” _
& “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2”)
Set colSoftware = objWMIService.ExecQuery _
(“Select * from Win32_Product where (Caption=’Symantec Endpoint Protection’)”)

For Each objSoftware in colSoftware
wscript.echo objSoftware.Version
Next

or just

REG query “HKLM\SOFTWARE\Symantec\Symantec Endpoint Protection\SMC” | FIND “ProductVersion”

 

 

vbscript to check windowsupdate.com

Set updateSession = CreateObject(“Microsoft.Update.Session”)

‘ Search windowsupdate.com for updates

Set updateSearcher = updateSession.CreateUpdateSearcher()

WScript.Echo “Searching for updates…” & vbCRLF

 Set searchResult = _

updateSearcher.Search(“IsInstalled=0 and Type=’Software’ and IsHidden=0”)

 WScript.Echo “List of updates available for server:”

 For I = 0 To searchResult.Updates.Count-1

    Set update = searchResult.Updates.Item(I)

    WScript.Echo I + 1 & “> ” & update.Title

Next

 If searchResult.Updates.Count = 0 Then

    WScript.Echo “There are no applicable updates.”

    WScript.Quit

End If