2

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
  • 146

1 Answers1

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

postanote
  • 5,136