r/PowerShell • u/Covid_Nipple420 • May 17 '26
Question End Task script is repeating back to me instead of executing
I have tried to make a script to close Webex when it reached a certain time but the CLI just repeats the command back to me instead of executing it. AI has no given me any useful suggestions so I am hoping someone on here could help me. Code is as follows:
Get-Process -Name "Webex" -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
Write-Host "Webex has been stopped." -ForegroundColor Green
3
Upvotes
12
u/tose123 May 17 '26
See if it's there:
Get-Process | Where-Object {$_.ProcessName -match "Webex"}Also, that write-host statement prints "... has been stopped" no matter the outcome of the previous statement.
So cases like:
Stop-Processfailedare not checked. It'll just always print has been stopped.
3
u/Ferretau May 17 '26
Is their a process called Webex? Is it running under the same account as your are running the powershell in or the powershell process elevated?
The code as written the Write-Host line will always be displayed regardless if it stops the process or not
4
u/hihcadore May 17 '26 edited May 17 '26
Drop the silently continue and it’ll tell you if the command is erroring.
When you’re having issues like this make what you’re running as verbose as possible.
Now you can see by variable what was pulled and see where the break point is.
If this is going to run unattended you’d want to wrap it in a try catch block and output the result to a logfile
Then look at the variables to get a better understanding of what’s going on
2
u/omglazrgunpewpew May 19 '26
Since you found
CiscoCollabHost.exein Details, try it without the .exe:Get-ProcessexposesProcessNamewithout the .exe extension, soCiscoCollabHost.exewon’t match by-Name.Also, small correction to one of the comments: PowerShell’s
-matchis case-insensitive by default. Overall, bigger issue here is process name vs display name vs executable name. Task Manager’s friendly app name is often lying in a very Windows way.5
u/grahamfreeman May 17 '26
How is that code called?
4
u/IdidntrunIdidntrun May 17 '26
Did you set the ExecutionPolicy or run the script with an ExecutionPolicy bypass? Also it'd be better to call the process Id instead of a simple string
1
u/thomsxD May 17 '26
What is the output without the -ErrorAction?
1
u/arslearsle May 17 '26
Put it in a try catch and log the exeption, if any, to a logfile using transcript…
1
u/giasone888 May 21 '26
Get-Process | Where-Object {$_.ProcessName -like "*Webex*"}
0
u/GnuInformation May 18 '26
Powershell is very "basic". . That "match" might be the hang up. It's case sensitive and usually 'non-float' .. if you modify your match sample to include wild -cards it might help.. I think you got lots of other help, but I would validate that search is giving you all possible matches first. And second that you then filter to get the one you want stopped. ** Or it iterates thru and kills all possible processes.