How to open image.png using a PowerShell script?

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.

G:\image.png

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


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

start G:\image.png

Or

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.