Table Of Contents

Calling PowerShell Commands

Version:
    Last Modified: November 6, 2020

    Create a custom execute to call a PowerShell command after you install a package. For example, you can invoke a PowerShell command to create a custom Windows shortcut that includes arguments.

    1. Select [System (32-bit)] in the Root drop-down.
    2. Set the Executable Path to the path of the PowerShell executable: WindowsPowerShell\v1.0\powershell.exe
    3. Enter the following PowerShell commands in the Arguments field to create a shortcut:

      -Command "$WScriptShell = New-Object -ComObject 'WScript.Shell'; $Shortcut = $WScriptShell.CreateShortcut('<ShortcutPath>.lnk'); $Shortcut.Arguments = '<Arguments>'; $Shortcut.TargetPath = '<TargetPath>'; $Shortcut.Save()"

      Replace <ShortcutPath> with the full path for the shortcut you want to create, <TargetPath> with the full path to the executable or directory the shortcut launches, and <Arguments> to pass to the shortcut operation.

      The following custom execute launches notepad.exe and opens an installed text file:

      -Command "$WScriptShell = New-Object -ComObject 'WScript.Shell'; $Shortcut = $WScriptShell.CreateShortcut('%programfiles%\SomeFolder\Notepad_Args.lnk'); $Shortcut.Arguments = '%programfiles%\SomeFolder\SomeTextFile.txt'; $Shortcut.TargetPath = '%system%\notepad.exe'; $Shortcut.Save()"

    4. Click OK.
    5. Build your package by selecting Build»Build All Packages.

    Recently Viewed Topics