I have an application that when opened sometimes opens several times. The application has one Process and background process but sometimes many can open.
I am trying to write a powershell script that launches the application and checks to see if it opened multiple and kills the processes that should not be there.
Start-Process -Filepath "path"
Get-Process -Name name* | Where-Object {$_.Id -ne $pid} | stop-process
This is the bit I have now but this closes all instances of the file name.
How can I just close the places where there are multiple instance.
Also, I can't hardcode a PID because it changes everytime it opens..
Thanks