• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 435
  • Last Modified:

locate .exe on remote PC

I need to query our network and determine which machines have certain apps installed.

I was hoping to have powershell read from a CSV with netbios names and output a list of PCs that have the exe on them.

What would a script like that look like?
1 Solution
Chris DentPowerShell DeveloperCommented:

Do you know where the exe file will be? Searching an entire file system is quite time-consuming, even if we went down the remoting road and had the client system do it for you.

Mike ThomasConsultantCommented:
This will scan your pc's and list all installed apps

Meir RivkinFull stack Software EngineerCommented:
hope you don't mind it's vbs.

the script ping first to check availability, then query installed apps on registry and log each program for each machine if installed or not.

it reads he machine list from a file (c:\temp\machines.txt)
the apps list are hardcoded but can be also read from a file.

i was checking 2 applications Safari & Windows Live Essentials, so the output log should be something like this.

Safari could not be found
Windows Live Essentials could not be found

Safari could not be found
Windows Live Essentials could not be found

Safari could not be found
Windows Live Essentials could not be found

[s002] is unavailable

[s003] is unavailable

Safari could not be found
Windows Live Essentials was found

Safari could not be found
Windows Live Essentials could not be found

Safari could not be found
Windows Live Essentials was found

const APPS_LIST = "Safari,Windows Live Essentials"
const MACHINES_LIST_FILE = "c:\temp\machines.txt"

set objFSO = createobject("scripting.filesystemobject")
set objFile = objFSO.OpenTextFile(MACHINES_LIST_FILE, 1)
arrMachines = Split(objFile.ReadAll, vbNewLine)

Set objTextFile = objFSO.OpenTextFile ("c:\temp\apps.log", 2, True)

for each strComputer in arrMachines
	if Trim(strComputer) <> "" then
		if Ping(strComputer) = false then
			objTextFile.WriteLine "[" & strComputer & "]" & " is unavailable"
			On error resume next
			arrIA = getApps(strComputer)

			objTextFile.WriteLine "[" & strComputer & "]"

			If IsArray(arrIA) Then
				For Each prog In Split(APPS_LIST, ",")
					For Each strApp In arrIA
						if InStr(Trim(strApp), Trim(prog)) > 0 then
							exit for
						end if
					if found = false then
						objTextFile.WriteLine prog & " could not be found"
						objTextFile.WriteLine prog & " was found"
					end if
				objTextFile.WriteLine "[" & strComputer & "] is unavailable" 
			End If
		end if
	end if


wscript.echo "done"

Function Ping(strHost)

    dim objPing, objRetStatus

    set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
      ("select * from Win32_PingStatus where address = '" & strHost & "'")

    for each objRetStatus in objPing
        if IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 then
			Ping = False
            Ping = True
        end if
End Function 

Function getApps(strComputer)
	strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
	Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}//" & strComputer & "/root/default:StdRegProv")

	If Err.Number > 0 Then
		getApps = False
		Exit Function
	End If

	objReg.EnumKey HKLM, strKey, arrSubkeys

	arrInstalledApps = Array()

	For Each strSubkey In arrSubkeys

		intRet1 = objReg.GetStringValue(HKLM, strKey & strSubkey, "DisplayName", strValue1)
		If intRet1 <> 0 Then
			objReg.GetStringValue HKLM, strKey & strSubkey, "QuietDisplayName", strValue1
		End If

		If InStr(strValue1, "Hotfix") Or InStr(strValue1, "Security Update") Or InStr(strValue1, "Update for Windows") Then
		Elseif strValue1 <> "" Then
			ReDim Preserve arrInstalledApps(UBound(arrInstalledApps) + 1)
			arrInstalledApps(UBound(arrInstalledApps)) = strValue1
		End If
	getApps = arrInstalledApps
End Function

Open in new window

servers.txt contains a list of servernames
$Servers = Get-Content C:\Temp\Servers.txt
$SearchLocation = "Program Files"
$SearchFor = "programname.exe"

Foreach ($Server in $Servers) {
$Results = Get-ChildItem "\\$Server\c$\$SearchLocation" -filter $SearchFor -recurse
	If ($Results -ne $Null) {
	$Results | %{$_.Fullname}

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now