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

Kiers, P (Peter) 61 Reputation points

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



Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,409 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 45,111 Reputation points

    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