This cmdlet is part of the Vexasoft Cmdlet Library. You can download it now or click here to find out more.



Generates an executable line for launching Windows Powershell scripts.


  • Get-PSLaunchLine [-Script] [-ImportModule] [-ImportVexasoftCmdlets] [-ImportSystemModules] [-ExitOnExecution] [-RunHidden] [-AsObject]


The Get-PSLaunchLine cmdlet creates a string that can be used to launch Windows Powershell scripts for use in shortcuts, scheduled tasks and the registry. Used in conjunction with the Add-ToStartup cmdlet, Get-PSLaunchLine can be used to specify scripts that should be run at user logon.


  • Script The script to launch when the Powershell session loads.
  • ImportModule Import the specified module when launching the Powershell session.
  • ImportVexasoftCmdlets Import the Vexasoft Cmdlet Library when launching the Powershell session.
  • ImportSystemModules Import all available modules when launching the Powershell session. This will also import the Cmdlet Library module but not make the Vexasoft Cmdlets available. Use the ImportVexasoftCmdlets parameter if you also wish to load the Vexasoft Cmdlets into the session.
  • ExitOnExecution Exit the Powershell session after the specified script has run. If this parameter is used but no script has been specified in the Script parameter, the Powershell session will load and exit immediately.
  • RunHidden Run the Powershell session hidden so that it is not visible to end users.
  • AsObject Output as an object, rather than a string. For use with the Set-StartUpApplication cmdlet.


Get-PSLaunchLine does not accept pipeline input.


Get-PSLaunchLine outputs a system.string by default, but will output a Vexasoft.PSLaunchLine object if the AsObject parameter is specified.


There are no additional notes for the Get-PSLaunchLine cmdlet.

Example 1

This command will retrieve a basic launch line for running Windows Powershell:


Example 2

This command will create a launch line that will execute script \\Server01\AdminScript1.ps1 in Powershell:

C:\PS>Get-PSLaunchLine -Script \\Server01\AdminScript1.ps1

Example 3

This command will create a launch line for launching Powershell with the ActiveDirectory snapin and executing script \\Server01\AdminScript1.ps1:

C:\PS>Get-PSLaunchLine -Script \\Server01\AdminScript1.ps1 -ImportModule ActiveDirectory

Example 4

This command will create a launch line for launching Powershell with all system modules, before executing the script AutomationScript1 and exiting on completion of the script:

C:\PS>Get-PSLaunchLine -Script \\Server01\AutomationScript1.ps1 -ImportSystemModules -ExitOnExecution

Example 5

Identical to the previous example, this command will generate a launch line that will also run Powershell hidden from the user and without presenting a command prompt.

C:\PS>Get-PSLaunchLine -Script \\Server01\AutomationScript1.ps1 -ImportSystemModules -ExitOnExecution -RunHidden

Example 6

This command will generate an object with a name and execution line for use with other cmdlets, such as Set-StartUpApplication. When piped into the Set-StartUpApplication cmdlet the above line would create a startup task in Windows to launch the \\Server01\AutomationScript1.ps1 script in a hidden window at user logon:

C:\PS>Get-PSLaunchLine -Script \\Server01\AutomationScript1.ps1 -AsObject -RunHidden -ExitOnExecution