It seems like this should be simple but I have tried for better than an hour to get it to work properly without success. I have a working PowerShell command that I want to execute from a Windows shortcut.
The command is:
Start-Process -filepath "C:\Program Files\One Identity\Active Roles\7.3\Console\ActiveRoles.msc" -Verb RunAsUser
This works as expected. It opens the GUI prompt to enter user/pass.
My expectation was that I could just create a shortcut with the target:
powershell.exe -command '& {Start-Process -filepath "C:\Program Files\One Identity\Active Roles\7.3\Console\ActiveRoles.msc" -Verb RunAsUser}'
That doesn't work. It flashes up but doesn't execute.
I tried running the command from PowerShell and it gave me Start-Process : A positional parameter cannot be found that accepts argument 'Identity\Active'
So I am now using an alternate path to avoid spaces:
powershell.exe -command '& {Start-Process -filepath "C:\Progra~1\ONEIDE~1\ACTIVE~1\7.3\Console\ActiveRoles.msc" -Verb RunAsUser}'
This still doesn't work. It won't run in PowerShell, so it won't work in a shortcut. It just gives me a new line in the PS window with no feedback.
Running just Start-Process -filepath 'C:\Progra~1\ONEIDE~1\ACTIVE~1\7.3\Console\ActiveRoles.msc' -Verb RunAsUser
works fine.
I have tried a bunch of variations on this. I have tried with and without quotes, with and without spaces, with and without the &{}. I tried adding the single-line command to powershell script and calling that from a shortcut. This still doesn't work. The call executes without error but does not launch the .msc.
The goal of this is really to have a Windows shortcut that will launch the .msc with the -RunAsUser flag, but I am also interested more generally in how to get a pwershell command to run from a shortcut. Most of what I am finding in other posts is using bash commands with a commandline prompt, which isn't what I want. I feel like I must be missing something obvious here. This should be simple.
powershell.exe -executionpolicy bypass -file "c:\temp\script.ps1"
PowerShell -command "mycommand 'my path'"
- see superuser.com/questions/1080239/run-powershell-command-from-cmd/…