1

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.

Jeramy
  • 136
  • 1
  • 7
  • Could it be something with execution policy? Maybe set what you have to a .ps1 file and then call this from the shortcut: `powershell.exe -executionpolicy bypass -file "c:\temp\script.ps1"` – Narzard Nov 29 '22 at 20:21
  • The problem is the spaces in the path. Use PowerShell ISE to determine what value exactly you are currently passing and update your question – Ramhound Nov 29 '22 at 21:31
  • You need use quotes like this `PowerShell -command "mycommand 'my path'"` - see https://superuser.com/questions/1080239/run-powershell-command-from-cmd/1080336#1080336 – SimonS Nov 30 '22 at 07:53
  • @Narzard I am sure it is firing. I can see the output of a write-output but it doesn't launch the .msc – Jeramy Nov 30 '22 at 13:39
  • @Ramhound I have tried without spaces as shown above without success. – Jeramy Nov 30 '22 at 13:41
  • @SimonS I tried reversing my usage of quotes as you suggested but still have no success getting the command to execute properly. – Jeramy Nov 30 '22 at 13:41
  • So, before messing with PS, are you saying, you've already created a desktop shortcut to ```ActiveRoles.msc```, which you can double-click to run successfully? Then, you opened that shortcut's properties and copied the target path string, and pasted that into PS console/ISE/VSCode and it won't run? Or, are you just manually typing this out? ***.msc*** files are executed by calling ```msc.exe (via cmd.exe)``` under the covers even when run from PS. Are you saying that only this ***msc*** file does not fire? Meaning, you've tried other default ***.msc*** file locations successfully? – postanote Nov 30 '22 at 18:02
  • @postanote I have a working shortcut with a target "C:\Program Files\One Identity\Active Roles\7.3\Console\ActiveRoles.msc" which works fine, but does not prompt for creds. If I drop it in powershell with dot execution it runs fine .`'C:\Program Files\One Identity\Active Roles\7.3\Console\ActiveRoles.msc'` The goal is to use -Verb RunAsUser so every time the shortcut is run it prompts for user creds, This works from PS with `Start-Process -filepath 'C:\Progra~1\ONEIDE~1\ACTIVE~1\7.3\Console\ActiveRoles.msc' -Verb RunAsUser` but not from a shortcut – Jeramy Dec 01 '22 at 15:34
  • You should not expect this to work from a shortcut as written. Start-Process is a PS cmdlet, which can only be run when in a PS session. – postanote Dec 02 '22 at 01:59

1 Answers1

0

Point of note. As per the Start-Process help docs.

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/start-process?view=powershell-7.2

-Verb Specifies a verb to use when this cmdlet starts the process. The verbs that are available are determined by the filename extension of the file that runs in the process.

The following table shows the verbs for some common process file types.

  • File type Verbs

  • .cmd Edit, Open, Print, RunAs, RunAsUser

  • .exe Open, RunAs, RunAsUser

  • .txt Open, Print, PrintTo

  • .wav Open, Play

Note that .msc is not on the list.

Windows knows what to do with shortcuts with targets like this...

'C:\Program Files\One Identity\Active Roles\7.3\Console\ActiveRoles.msc'

... files with .msc tells Windows to launch msc.exe to execute .msc files because that executable is how Windows has it mapped.

Windows has no idea what to do with this...

Start-Process 'C:\Program Files\One Identity\Active Roles\7.3\Console\ActiveRoles.msc'

... because Start-Process, is not an executable, it is only viable in a running/instantiated PowerShell session.

You have to do the below, for what you are after in a shortcut.

powershell "Start-Process 'C:\Program Files\One Identity\Active Roles\7.3\Console\ActiveRoles.msc'"

PowerShell must first be launched, to run PS cmdlets, then the path to anything else you want that cmdlet to do.

Demo: enter image description here

postanote
  • 4,589
  • 2
  • 7
  • 7
  • Have you been able to get this to work using -Verb RunAsUser? The goal is to have a shortcut that opens the user credentials dialog. One of the first things I tried was a shortcut calling powershell with the command `powershell "Start-Process 'C:\Program Files\One Identity\Active Roles\7.3\Console\ActiveRoles.msc' -Verb RunAsUser"` This doesn't work for me. – Jeramy Dec 02 '22 at 16:31
  • Though the docs for Start-Process don't explicitly list .msc, the command `Start-Process -filepath "C:\Program Files\One Identity\Active Roles\7.3\Console\ActiveRoles.msc" -Verb RunAsUser` works as expected from a PowerShell window. I am trying to produce this result from a shortcut. – Jeramy Dec 02 '22 at 16:33