Setting the below $usbDriveLetter variable to automatically find the USB drive letter, and using that variable to open an image on the USB doesn't work. It literally prints "G:\image.png" in the cmd.

$usbDriveLetter = (gwmi win32_volume -f 'label=''USB_NAME_HERE''').Name;
"$usbDriveLetter" + "image.png"

But if I don't use a var and make "G:\" static in the PowerShell script, the image opens just fine.


So what am I doing wrong here? How do we dynamically open images using ps1 scripts?

  • If the suggested answer satisfies you, please consider mark it, as it will mark the question as answered. – arieljannai Mar 10 '18 at 17:05

You can use the Start-Process (or its start alias) command.

start G:\image.png


start $usbDriveLetter"image.png"

It will open your image with the default application set to open png files (or ask you to choose one if no default image viewer is set).

Note from the comments, by flolilolilo: Notice that just calling a variable will print its value. In your case, you actually want to use it as the Start-Process command parameter.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.