Hello Scripters,
I am attempting to apply windows updates to a vhdx using add-windows package, in reference to the following article:
http://www.server-talk.eu/2015/01/19/virtual-machine-template-patching/
When I run the script within my test environment I get "The system cannot find the file specified." for every file it finds on my wsus server. I have verified the file(s) exist and are accessible. I have also moved the update files to my local drive and rerun the test, same issue.
To verify my image is not the problem, I have mounted the vhdx, run the following code against it, and then unmounted and saved the vhdx:
dism /image:c:users\<redacted>\desktop\templatepatching /cleanup-image /restorehealth
What are my next steps? Test code below:
# Path to VHD(x) VM Template
#$VMTemplate = "\\INFRA01.backslash.li\MSSCVMMLibrary\VHDs\TP_WS2012R2_disk_1.vhdx"
$VMTemplate = "C:\users\<redacted>\desktop\VMMTesting\WTAWIN2K12R2STD-40GB.vhdx"
$TempDirectory = "C:\Users\<redacted>\Desktop\TemplatePatching"
Mount-WindowsImage -ImagePath $VMTemplate -Path $TempDirectory -Index 1
# Get all available Updates from WSUS
$WsusServer = "updateserver.contoso.com"
$UpdatelistCab = Get-ChildItem -Path "\\$WsusServer\WsusContent" -Include *.cab -Recurse -File
$UpdatelistMsu = Get-ChildItem -Path "\\$WsusServer\WsusContent" -Include *.msu –Recurse -File
Foreach ($UpdateCab in $UpdatelistCab)
{$UpdateReady = Get-WindowsPackage -PackagePath $UpdateCab -Path $TempDirectory
If ($UpdateReady.PackageState -eq "installed")
{Write-Output $UpdateReady.PackageName "is already installed"}
Elseif ($UpdateReady.Applicable -eq "true")
{Add-WindowsPackage -PackagePath $Updatecab.Directory -Path $TempDirectory}}
ForEach ($UpdateMsu in $UpdatelistMsu)
{Add-WindowsPackage -PackagePath $UpdateMsu.Directory -Path $TempDirectory}
# Dismount the VHD / VHDX
Dismount-WindowsImage -Path $TempDirectory -Save
#DisMount-WindowsImage -Path $TempDirectory -Discard