How to start a shortcut with powershell which has a variable in the path.

Kiers, P (Peter) 61 Reputation points
2021-02-04T21:57:43.237+00:00

Dear experts,

I want to start a shortcut from the Start Menu with Powershell. f.e:

start-process -FilePath 'C:\Programmas\Start Menu\xxxxxxxxxx\Programs\notepad.lnk'

The xxxxxx in the path is a variable with changes all the time.

Is it possible to start the shortcut which has a variable in the path.

How can i start a shortcut which has a variable in the path OR
maybe capture the string of a shortcut and then starting it.

Who knows the answer and is willing to help me

Greetings,

P

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 47,901 Reputation points
    2021-02-04T22:19:19.243+00:00

    There's nothing magical about using a variable in this case . . . provided you use double quotes to surround the path value. In the example you gave, the use of single quotes prevents the interpolation of any variables in the string.

    $Var = "A_Variable_String"
    Start-Process -FilePath "C:\Programmas\Start Menu\$Var\Programs\notepad.lnk"
    
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.