Param($PackageDir,$TargetVhd,$mountdir) if ($PSBoundParameters.Count -ne 2) { Write-host "Error: -TargetVhd -MountDir " ;exit } If ( -not (Test-Path $targetvhd)) { Write-host "Error: -TargetVhd does not exist." ;exit } If ( -not (Test-Path $mountdir)) { Write-host "Error: -MountDir does not exist." ;exit } $success = $true DISM /Mount-Image /Imagefile:$targetvhd /index:1 /mountdir:$mountdir #if (Test-Path -Path $mountdir"\Windows") { if ($LASTEXITCODE -eq 0) { DISM /Image:$mountdir /Cleanup-Image /StartComponentCleanup /ResetBase if (!($LASTEXITCODE -eq 0)) { $success = $false Write-Host "Failed: "$package } } else { "Failed: DISM /Mount-Image" "Failed: VHD(x) was not updated." exit } if ($success) { DISM /Unmount-Image /mountdir:$mountdir /Commit if (!($LASTEXITCODE -eq 0)) { DISM /Unmount-Image /mountdir:$mountdir /Discard "Failed: DISM /Commit, VHD(x) was not updated. " exit } } else { DISM /Unmount-Image /mountdir:$mountdir /Discard "Failed: DISM /Cleanup-Image, VHD(x) was not updated." exit } exit