[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Script to return installed third party software and patches

Posted on 2011-10-06
8
Medium Priority
?
308 Views
Last Modified: 2012-05-12
I need a script (vbscript or powershell) that will check a list a computers and return the ones that has a specific third party software (i.e. adobe reader) and the list of software update installed for that third party software. All the workstations are winxp SP2 and up. The output can be txt or csv.

Any help is appreciated.
0
Comment
Question by:lo_oscar
  • 4
  • 4
8 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 36929631
Hi, try this.  It reads computer names from computers.txt

Regards,

Rob.
On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

strComputers = "computers"
strResults = "results.csv"
strProduct = "Adobe"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1
Set objFile = objFSO.OpenTextFile(strComputers, ForReading, False)
Set objResults = objFSO.CreateTextFile(strResults, True)

objResults.WriteLine """Computer"",""Product"",""Install Date"""

While Not objFile.AtEndOfStream
	strComputer = Trim(objFile.ReadLine)
	If strComputer <> "" Then
		If Ping(strComputer) = True Then
			On Error Resume Next
			Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
			Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Product WHERE Name LIKE '%" & strProduct & "%'", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
			If Err.Number = 0 Then
				For Each objItem In colItems
					objResults.WriteLine """" & strComputer & """,""" & objItem.Name & """,""" & objItem.InstallDate & """"
				Next
			Else
				objResults.WriteLine """" & strComputer & """,""<ERROR " & Err.Number & ": " & Err.Description & ">"","""""
			End If
			Err.Clear
			On Error Goto 0
		Else
			objResults.WriteLine """" & strComputer & """,""<OFFLINE>"","""""
		End If
	End If
Wend

WScript.Echo "Finished"

Function Ping(strComputer)
	Dim objShell, boolCode
	Set objShell = CreateObject("WScript.Shell")
	boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
	If boolCode = 0 Then
		Ping = True
	Else
		Ping = False
	End If
End Function

Open in new window

0
 

Author Comment

by:lo_oscar
ID: 36943054
Got some syntax errors at line 3, 4 and 17.
0
 

Author Comment

by:lo_oscar
ID: 36943903
Sorry I tried again and it worked. however it does not return any patches for the application, it only list the installed applicaiton. any ideas?
0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 
LVL 65

Expert Comment

by:RobSampson
ID: 36945152
It is only looking in the Add/Remove Programs entries (more or less) for anything that is like
*program*

depending on what you put in strProduct.  What is the name of such an update in Add / Remove Programs?  Is it a different title?

Rob.
0
 

Author Comment

by:lo_oscar
ID: 36945962
Looks like the value I'm looking for is not in the win32_product class, here's what I found on the web:

http://us.generation-nt.com/how-retrieve-software-updates-wmi-help-26288802.html
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 2000 total points
ID: 36946072
OK, well combining bits of that with my code, try this.

Regards,

Rob.
On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

strComputers = "computers.txt"
strResults = "results.csv"
strProduct = "Adobe"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1
Const HKLM = &H80000002
Set objFile = objFSO.OpenTextFile(strComputers, ForReading, False)
Set objResults = objFSO.CreateTextFile(strResults, True)

objResults.WriteLine """Computer"",""Product"",""Install Date"""

While Not objFile.AtEndOfStream
	strComputer = Trim(objFile.ReadLine)
	If strComputer <> "" Then
		If Ping(strComputer) = True Then
			On Error Resume Next
			Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
			If Err.Number = 0 Then
				' Method 1: Win32_Product class
				Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Product WHERE Name LIKE '%" & strProduct & "%'", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
				For Each objItem In colItems
					strDisplayName = objItem.Name
					strInstallDate = ""
					On Error Resume Next
					strInstallDate = objItem.InstallDate
					Err.Clear
					On Error GoTo 0
					If strInstallDate <> "" Then strInstallDate = Right(strInstallDate, 2) & "-" & MonthName(Mid(strInstallDate, 5, 2)) & "-" & Left(strInstallDate, 4)
					objResults.WriteLine """" & strComputer & """,""" & strDisplayName & """,""" & strInstallDate & """"
				Next
				' Method 2: "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" key in the registry
				Set oRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "/root/default:StdRegProv")
				strBaseKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
				intReturn = oRegistry.EnumKey(HKLM, strBaseKey, arrSubKeys)
				If intReturn = 0 And IsNull(arrSubKeys) = False Then
					For Each strKey In arrSubKeys
						strValue = ""
						intReturn = oRegistry.GetStringValue(HKLM, strBaseKey & strKey, "DisplayName", strDisplayName)
						If intReturn = 0 Then
							If IsNull(strDisplayName) = False Then
								If IsEmpty(strDisplayName) = False Then
									If InStr(LCase(strDisplayName), LCase(strProduct)) > 0 Then
										strInstallDate = ""
										On Error Resume Next
										intReturn = oRegistry.GetStringValue(HKLM, strBaseKey & strKey, "InstallDate", strInstallDate)
										Err.Clear
										On Error GoTo 0
										If strInstallDate <> "" Then strInstallDate = Right(strInstallDate, 2) & "-" & MonthName(Mid(strInstallDate, 5, 2)) & "-" & Left(strInstallDate, 4)
										objResults.WriteLine """" & strComputer & """,""" & strDisplayName & """,""" & strInstallDate & """"
									End If
								End If
							End If
						End If
					Next
				End If
			Else
				objResults.WriteLine """" & strComputer & """,""<ERROR " & Err.Number & ": " & Err.Description & ">"","""""
			End If
			Err.Clear
			On Error Goto 0
		Else
			objResults.WriteLine """" & strComputer & """,""<OFFLINE>"","""""
		End If
	End If
Wend

WScript.Echo "Finished"

Function Ping(strComputer)
	Dim objShell, boolCode
	Set objShell = CreateObject("WScript.Shell")
	boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
	If boolCode = 0 Then
		Ping = True
	Else
		Ping = False
	End If
End Function

Open in new window

0
 

Author Closing Comment

by:lo_oscar
ID: 36964429
thank you!
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 36965463
No problem. Thanks for the grade.

Regards,

Rob.
0

Featured Post

A Cyber Security RX to Protect Your Organization

Join us on December 13th for a webinar to learn how medical providers can defend against malware with a cyber security "Rx" that supports a healthy technology adoption plan for every healthcare organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Loops Section Overview

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question