Once I needed to launch a specific program from a USB stick during a SCCM Task Sequence. In this case it was a cmd script which needed to be launched outside the Task Sequence.
Underneath my Powershell script to do so. It searches for a specific directory (<UNIQUE DIRECTORY>) which only exists on the USB stick. By doing so we can filter the drive letter and store it in a variable. After that we execute the specific file (<SPECIFY FILE>).
A very simple but effective script which u can also use on other drives than a USB Stick.
# Scriptname: Install.ps1 # Description: Start a program from a USB drive without knowing the driveletter # Author: Marco Nuijens # Date: 19-01-2017 # Changelog: # ... # Set variable for "USB drive" through a search for a unique directory only available on de USB drive. $USBDrive = get-psdrive |where {$_.Root -match ":"} |% {if (Test-Path ($_.Root + "<UNIQUE DIRECTORY>")){$_.Root}} # Start specific file on the USB driver $ExtractImage = $USBDrive + "<SPECIFY FILENAME>" cmd.exe /c $ExtractImage