I'm trying to create a PowerShell script that closes Webex at a specific time. When I type the command manually, I can stop the process after identifying the correct executable, but saving the command as a .ps1 file causes a brief red error message and Webex remains open. The original command was:
Get-Process -Name "Webex" -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
Write-Host "Webex has been stopped." -ForegroundColor Green
How can I identify the correct process and make the script show or log any errors instead of hiding them?
3 Answers
Remove `-ErrorAction SilentlyContinue` while troubleshooting. Those switches are hiding the useful error message, which is probably why the script appears to just repeat or do nothing. Also, the `Write-Host` line always prints success even if no process was found or stopping it failed. Test the process first and only print success when a process was actually stopped.
Task Manager’s friendly display name, process name, and executable filename can all differ. `Webex` may be the app label while the real process is something like `CiscoCollabHost`. Run `Get-Process` and use the exact `ProcessName` value, without the `.exe` extension. Also verify that the process is running under your account and that PowerShell has enough permissions to terminate it.
The name shown in Task Manager isn’t always the name PowerShell uses. Check the actual process names with:
Get-Process | Where-Object {$_.ProcessName -like "*Webex*"}
`Get-Process -Name` expects the process name without `.exe`. If the executable is `CiscoCollabHost.exe`, use:
Get-Process -Name CiscoCollabHost | Stop-Process -Force
You can also inspect the result before stopping anything:
$p = Get-Process | Where-Object {$_.ProcessName -like "*Webex*"}
$p
$p | Stop-Process -Force

That command works when I type it directly in PowerShell, but running the saved .ps1 file briefly shows red error text and doesn’t close Webex.