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.

9
  • 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
    Commented Nov 29, 2022 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
    Commented Nov 29, 2022 at 21:31
  • You need use quotes like this PowerShell -command "mycommand 'my path'" - see superuser.com/questions/1080239/run-powershell-command-from-cmd/…
    – SimonS
    Commented Nov 30, 2022 at 7: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
    Commented Nov 30, 2022 at 13:39
  • @Ramhound I have tried without spaces as shown above without success.
    – Jeramy
    Commented Nov 30, 2022 at 13:41

1 Answer 1

1

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

2
  • 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
    Commented Dec 2, 2022 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
    Commented Dec 2, 2022 at 16:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .