New
#21
Regarding my previous post, I realised that there's a catch in creating shortcuts for PowerShell commands, something that might go unnoticed if user is not familiar with it.
So, the PowerShell command to close each and every application which is currently running is as told in my previous post:
Get-Process | Where-Object {$_.MainWindowTitle -ne ""} | stop-process
Notice that I have highlighted the pair of double quotes in the command with bold red font.
Now, if you want to create a shortcut to run this command, you use syntax as follows:
PowerShell -command "your PS command here"
Your PowerShell command comes between double quotes. The thing is, command line interface misinterprets double quotes within double quotes and the command fails. When you run a PowerShell command like the one in this post from CLI, a shortcut, WIN + R or Command Prompt, you must change all double quotes in your PS command to single quotes, otherwise the command fails.
So, in order to make this as a shortcut, or run it from WIN + R, you must change double quotes to single quotes. Use following command in shortcut (single quotes highlighted red):
PowerShell -command "Get-Process | Where-Object {$_.MainWindowTitle -ne ''} | stop-process"
Short: when run from PowerShell, use double quotes. When run from shortcut or WIN + R, use single quotes.
Kari