[Powershell] mount-diskimage unter Windows Server 2012 und Alternativen

Gepostet am: May 02, 2014 5:37:35 PM

Mit folgenden Powershell-Befehlen kann man seit Windows 8 / Windows Server 2012 iso-Files mounten und dergleichen:

Mit dem falschen Benutzer ausgeführt, bekommt man jedoch die Fehlermeldung "mount-diskimage : A required privilege is not held by the client." Die Ursache findet sich auch recht schnell auf Technet

"To mount a VHD file, administrator privileges is required. Administrator privileges are not needed to mount an ISO file on Windows® 8. On Windows Server® 2012, only an administrator is allowed to mount or eject an ISO file." [Quelle]

mount-iso.ps1 -isoPath "D:\XYZ.iso"

param(     [string]$isoPath) #Script$isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) if ($isoPath) {     if ((Test-Path $isoPath) -eq $false) {         Write-Host "Die zu ladende ISO-Datei kann nicht gefunden werden"     } else {         Write-Host "Laden der Datei: $isoPath"         if ($isAdmin -eq $false) #if not Admin        {             $targetfile = $PSScriptRoot + "tmp_mount_iso_as_admin.ps1"             if (Test-Path $targetFile) {Remove-Item $targetFile -Force}             $openArgument = ("-ImagePath '$isoPath'").Replace("'",[char]34)             Write-Host $openArgument             "Mount-DiskImage $openArgument" >> $targetfile             $arg = "-file $targetfile"             start-process powershell -verb runas –argumentlist $arg         } else { #if admin            Mount-DiskImage -ImagePath $isoPath         }     } } else {     Write-Host "Geben Sie mit -isoPath den Pfad zur ISO-Datei an" }

Da ich den Registry Key respektive die Group Policy noch nicht gefunden haben, mit der man mount-diskimage für alle Benutzer verfügbar macht, und das oben erwähnte Skript auch nicht die optimalste Lösung ist, verwende ich "Virtual CloneDrive". Das kann man auch recht einfach über die Befehlszeile steuern.

mounten:

vcdmount /d=0 C:\isofile.iso

unmount:

vcdmount /d=0 /u

Die 2 dazugehörigen powershell-Funktionen

Mount / UnMount

function mountISO([string]$isoPath, [string]$DriveNumber) {     if ((Test-Path($isoPath)) -eq $true) {         Write-Host "Searching (vcdmount.exe) ..."          $files = Get-ChildItem -Path C:\ -File "vcdmount.exe" -Recurse -ErrorAction SilentlyContinue         $cmd = $files[0].FullName         if ((Test-Path($cmd)) -eq $true) {             $args = ("/d=$DriveNumber '$isoPath'").Replace("'",[char]34)             Write-Host "$isoPath wird gemountet"             $p = Start-Process $cmd -ArgumentList $args -wait         } else {             Write-Host "vcdmount.exe wurde nicht gefunden"         }     } }  function unmountISO([string]$DriveNumber) {     Write-Host "Searching (vcdmount.exe) ..."      $files = Get-ChildItem -Path C:\ -File "vcdmount.exe" -Recurse -ErrorAction SilentlyContinue     $cmd = $files[0].FullName     if ((Test-Path($cmd)) -eq $true) {                 $args = ("/d=$DriveNumber /u")         Write-Host "CD/DVD wird unmountet"                 $p = Start-Process $cmd -ArgumentList $args -wait         } else {         Write-Host "vcdmount.exe wurde nicht gefunden"     }             }

andere Methoden siehe auch:

weiterführende Literatur: