I made the below PowerShell functions for mounting and unmounting ISOs. I used Virtual Clone Drive (VCD). The downside, is it seems I can’t control which letter it assigns from the command line. And the function below always unmounts any ISOs prior to mounting the new one. At least that happens with the version of VCD I’ve been using.
# Mounts the specified ISO, and returns the Drive letter assigned to it
function MountISO([string] $fileNamePath)
{
try
{
$cmd = "C:\VirtualCloneDrive\vcdmount.exe"
Write-Log $logFile $cmd 0
Write-Log $logFile $fileNamePath 0
#invoke-expression $cmd
start-process -FilePath $cmd -ArgumentList $fileNamePath
# take pause to allow the mounting command to complete and the OS to do its part in making it available to the system.
start-sleep -s 10
# The newly mounted ISO is the last logical disk in the list.
$psDrives = Get-WmiObject -Class Win32_LogicalDisk
# The deviceID property represents the drive letter (i.e. "E:")
return $psDrives[$psDrives.Count - 1].DeviceID
}
catch
{
$err = $Error[0].Exception
Write-Log $logFile $err 2
return ""
}
}
# Unmounts any ISOs still mounted.
function UnmountISO
{
$cmd = "C:\VirtualCloneDrive\vcdmount.exe"
$cmd += " /u /h /p"
invoke-expression $cmd
}
No comments:
Post a Comment