[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

locate .exe on remote PC

Posted on 2010-08-25
5
Medium Priority
?
430 Views
Last Modified: 2012-05-10
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?
0
Comment
Question by:clcuser
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 71

Expert Comment

by:Chris Dent
ID: 33529137

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.

Chris
0
 
LVL 24

Expert Comment

by:Mike Thomas
ID: 33529152
This will scan your pc's and list all installed apps

http://www.steelsonic.com/sione.htm
0
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 33529326
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.


[meirpc]
Safari could not be found
Windows Live Essentials could not be found

[s004]
Safari could not be found
Windows Live Essentials could not be found

[s001]
Safari could not be found
Windows Live Essentials could not be found

[s002] is unavailable

[s003] is unavailable

[rana]
Safari could not be found
Windows Live Essentials was found

[markg]
Safari could not be found
Windows Live Essentials could not be found

[ilyak2]
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)
objFile.Close

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

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

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

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

objTextFile.Close

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
        else
            Ping = True
        end if
    next
End Function 

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

	If Err.Number > 0 Then
		getApps = False
		Err.Clear
		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
			'nothing
		Elseif strValue1 <> "" Then
			ReDim Preserve arrInstalledApps(UBound(arrInstalledApps) + 1)
			arrInstalledApps(UBound(arrInstalledApps)) = strValue1
		End If
	Next
	
	getApps = arrInstalledApps
End Function

Open in new window

0
 
LVL 6

Accepted Solution

by:
rwskas earned 2000 total points
ID: 33577435
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) {
	"$Server"
	"----------------"
	$Results | %{$_.Fullname}
	}
}

Open in new window

0

Featured Post

Looking for the Wi-Fi vendor that's right for you?

We know how difficult it can be to evaluate Wi-Fi vendors, so we created this helpful Wi-Fi Buyer's Guide to help you find the Wi-Fi vendor that's right for your business! Download the guide and get started on our checklist today!

Question has a verified solution.

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

Here in this article, you will get a step by step guidance on how to restore an Exchange database to a recovery database. Get a brief on Recovery Database and how it can be used to restore Exchange database in this section!
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
In this video we show how to create a Shared Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Sha…
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data…
Suggested Courses

650 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