I have been trying to get this powershell snippit working in UiPath and can’t seem to. It is giving the following error below. If I copy that directly from below and paste it in the PS console, it works perfectly. This is the snippit of code I use in the commandText:
"Get-Process | Where-Object {$_.ProcessName -eq " + Chr(34) + ProcessName + Chr(34) + “} | Stop-Process -Force -ErrorAction SilentlyContinue”
Kill Process: The term ‘Get-Process | Where-Object {$_.ProcessName -eq “chrome”} | Stop-Process -Force -ErrorAction SilentlyContinue’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
What am I doing wrong here? I also have a screenshot below of the entire thing. Thanks
@mick.pletcher
Can you try below approach?
- save this powershell code in a text file
- use read text file activity and save output
in a string variable
- use invoke powershell activity with properties as below:
a) under command text, provide the name of that string variable
b) check is script
@mick.pletcher
You can also try as below in command text directly.
“Get-Process | Where-Object {$_.ProcessName -eq ‘chrome’} | Stop-Process -Force -ErrorAction SilentlyContinue”
Hi @mick.pletcher
I think straight quotes issue try below past at notepad then check quotes then use in UiPath,
"Get-Process | Where-Object {$_.ProcessName -eq " + Chr(34) + ProcessName + Chr(34) + “} | Stop-Process -Force -ErrorAction SilentlyContinue”
Also, ensure ProcessName is a string variable and doesn’t contain extra quotes.
If you found helpful, Mark as a solution tick .
Happy Automation