Determine driveletter based on existing directory on a drive  

  RSS

Marco Nuijens
(@manu)
Member Admin
Joined: 2 years ago
Posts: 50
19/01/2017 11:15 am  

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

 


ReplyQuote
Share:
  
Working

Please Login or Register