检查.ISO是否已安装在powershell中,如果未安装,则安装

检查.ISO是否已安装在powershell中,如果未安装,则安装,powershell,batch-file,Powershell,Batch File,我有一个ISO文件,是从一张旧游戏光盘上复制的。但是为了让我玩这个游戏,我必须安装ISO。 我编写了一个小批量文件,运行.ps1PowerShell文件来装载ISO,然后在装载后运行EXE启动游戏。我的问题是,如果我多次运行脚本,它将再次装载ISO 我想检查ISO是否已连接,如果未连接则挂载,如果已连接则运行EXE 以下是我必须安装ISO的内容: 一批 动力壳 #mounts the image Mount-DiskImage -ImagePath "C:\Users\Allen\Documen

我有一个ISO文件,是从一张旧游戏光盘上复制的。但是为了让我玩这个游戏,我必须安装ISO。 我编写了一个小批量文件,运行
.ps1
PowerShell文件来装载ISO,然后在装载后运行EXE启动游戏。我的问题是,如果我多次运行脚本,它将再次装载ISO

我想检查ISO是否已连接,如果未连接则挂载,如果已连接则运行EXE

以下是我必须安装ISO的内容:
一批

动力壳

#mounts the image
Mount-DiskImage -ImagePath "C:\Users\Allen\Documents\Games\Hot Wheels Stunt 
Track Driver\setup\hot98\HotwheelsStuntTrack.iso"

此代码段仅在未装入映像时才会装入映像:

if(!(get-DiskImage -ImagePath C:\testshare\97001.ISO).Attached){
Mount-DiskImage -ImagePath C:\testshare\97001.ISO
}

为了补充Abhijith的回答,特别是提到一个我之前必须解决的问题:

$imagePath = "path to your ISO-file"

$mount = Mount-DiskImage -ImagePath $imagePath -PassThru
$driveLetter =  ($mount | Get-Volume).DriveLetter
$drive = $driveLetter + ":\\"

# PowerShell bug workaround
# Forces PowerShell to update drive info for its providers
# Not doing so makes Test-Path fail on freshly mounted drives

Get-PSDrive > $null

$setupPath = $drive + "the path to your exe on the mounted drive"
$setupArgs = "your .exe args"

if (!(Test-Path $setupPath)) {
  # ... Something went wrong ...
} else {
    $process = Start-Process $setupPath -ArgumentList $setupArgs -Wait -PassThru
    # You can check $process.ExitCode here    
}
$imagePath = "path to your ISO-file"

$mount = Mount-DiskImage -ImagePath $imagePath -PassThru
$driveLetter =  ($mount | Get-Volume).DriveLetter
$drive = $driveLetter + ":\\"

# PowerShell bug workaround
# Forces PowerShell to update drive info for its providers
# Not doing so makes Test-Path fail on freshly mounted drives

Get-PSDrive > $null

$setupPath = $drive + "the path to your exe on the mounted drive"
$setupArgs = "your .exe args"

if (!(Test-Path $setupPath)) {
  # ... Something went wrong ...
} else {
    $process = Start-Process $setupPath -ArgumentList $setupArgs -Wait -PassThru
    # You can check $process.ExitCode here    
}