Param($PackageDir,$TargetVhd,$mountdir) if ($PSBoundParameters.Count -ne 3) { Write-host "Error: -PackageDir -TargetVhd -MountDir " ;exit } If ( -not (Test-Path $packagedir)) { Write-host "Error: -PackageDir does not exist." ;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 } $packages = (Get-ChildItem -Path $packagedir| where {$_.extension -eq ".msu"} | Sort Name | %{$_.FullName}) $success = $true if ($packages.Count -gt 0){ DISM /Mount-Image /Imagefile:$targetvhd /index:1 /mountdir:$mountdir #if (Test-Path -Path $mountdir"\Windows") { if ($LASTEXITCODE -eq 0) { foreach ($package in $packages){ DISM /Add-Package /Image:$mountdir /PackagePath:$package 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 /Add-Package, VHD(x) was not updated." exit } } exit