1

Closed

Get-RunningProcesses Cmdlet

description

I am running into an issue with this cmdlet in that it is using -match instead of -eq. This is causing problems in my environment because I want to check for the existence of agent.exe. Get-RunningProcesses returns other processes matching agent so I receive Agent.exe, VPNAgent.exe and MBAMAgent. What are the ramifications of modifying this to look for exact processes?
Closed Apr 14, 2015 at 12:00 PM by mmashwani

comments

mmashwani wrote Apr 13, 2015 at 10:06 PM

I think to get it to work properly, you will have to change two lines in the function to the following:
## Escape special characters that interfere with regex and might cause false positive matches
[string[]]$processNames = $processObjects | ForEach-Object { [regex]::Escape($_.ProcessName) }

## Get all running processes and escape special characters. Match against the process names to search for to find running processes.
[System.Diagnostics.Process[]]$runningProcesses = Get-Process | Where-Object { $processNames -contains $_.ProcessName }

mmashwani wrote Apr 13, 2015 at 10:24 PM

There was a mistake above. Change it to:
## Create an array of process names to search for
[string[]]$processNames = $processObjects | ForEach-Object { $_.ProcessName }

## Get all running processes and escape special characters. Match against the process names to search for to find running processes.
[System.Diagnostics.Process[]]$runningProcesses = Get-Process | Where-Object { $processNames -contains $_.ProcessName }

mmashwani wrote Apr 14, 2015 at 11:58 AM

We have moved to a new homepage! You can now find us as http://psappdeploytoolkit.com.

This issue has been fixed in the latest 3.6.2 produciton release on our new repository on GitHub.
https://github.com/PSAppDeployToolkit/PSAppDeployToolkit