Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if .ISO is already mounted in powershell, if not then mount

I have an ISO file that I copied off of an old game disk. But in order for me to play the game, I have to mount the ISO. I wrote a small Batch file that runs the .ps1 PowerShell file to mount the ISO and then runs the EXE to start the game after it has been mounted. My problem is, if I run the script more than once it will mount the ISO again.

I want to check if the ISO is attached, mount it if it is not, or run the EXE if it is.

Here's what I have to mount the ISO:
Batch.

ECHO "Mounting Stunt Track Driver"

@ECHO off

Powershell.exe -executionpolicy remotesigned 
-File  "C:\Users\Allen\Documents\Games\Hot Wheels Stunt Track 
Driver\setup\hot98\mount.ps1"

start /d "C:\Users\Allen\Documents\Games\Hot Wheels Stunt Track 
Driver\setup\hot98" stunt.exe

PowerShell

#mounts the image
Mount-DiskImage -ImagePath "C:\Users\Allen\Documents\Games\Hot Wheels Stunt 
Track Driver\setup\hot98\HotwheelsStuntTrack.iso"
like image 451
Allen Rankin Avatar asked Feb 02 '26 01:02

Allen Rankin


1 Answers

this snippet will only mount image if it's not mounted :

if(!(get-DiskImage -ImagePath C:\testshare\97001.ISO).Attached){
Mount-DiskImage -ImagePath C:\testshare\97001.ISO
}
like image 160
ClumsyPuffin Avatar answered Feb 04 '26 00:02

ClumsyPuffin