powershellcommand-linepathusb-flash-drive

How to find my USB flash drive's path with PowerShell


I am preparing a ps1 file. It will install some programmes silently. But my programmes' setup files were saved in my USB flash drive. In my ps1 file,

cd E:\User\User_Setups

This path is my USB flash drive's path. But it will change on the other machine. Maybe G:\, F:\ etc. Naturally, I don't want to change this path for every different machines. How PowerShell find my USB flash drive's path by a command-line?


Solution

  • I added a VolumeLabel("MyToolBox") to my usb Stick and put following line in the profile.ps1:

    Get-DriveInfo | % { if( $_.VolumeLabel -eq "MyToolBox"){ Set-Location $_.Name; ./Startup.ps1}}
    

    Get-DriveInfo comes from the module Pscx: http://pscx.codeplex.com/ You need to import this in you profile too...

    The Startup.ps1 script is in the root of my usb stick and registers aliases on the stick for use in the session...