How to cd in Windows from internal drive to a connected USB drive without using the drive letter?

I am trying to change the directory in PowerShell from my pc to my usb drive. I want to automate this with a script but when I run the script on a different computer the drive letter of the USB device changes and I have to cd manually.

I've tried searching for alternative ways to cd to a USB drive, but didn't find a way, so can anyone suggest a solution?


If your USB drive has a name, then you can try to use the following to get the drive letter.

Get-Volume -FriendlyName "yourUSB_drivename" | Select DriveLetter

Store the result in a variable. Change "yourUDB_drivename" with the name you have given to the drive.


If it's the only removable drive attached at the time, this will also work:

'{0}:\' -f (Get-VOlume | ? DriveType -eq 'Removable').DriveLetter | cd