Appologize for my pool english first.

Every Month we need to patch and patch , yes you may have multiple ways to patch a online system , but when patching an offline image such as a VHD file in your SCVMM library or an installation WIM file in your install disc,  we generally need spend much time to do that . or you might left it away ,just like you have not seen them.

some days before ,i have found the script which was writen by Nicholas Dille, you can find it here https://gallery.technet.microsoft.com/Offline-Servicing-of-VHDs-df776bda ,but when i try to use it , i found i need to deel with some problems there.

  1. the script does not filter out non neccessary updates and invalid cabs ,so it will take long time to run in my environment.
  2. the script does not record which updates it applied, maybe the script will determine whether the update is suit for you ,but using dism to do this check takes long time.
  3. i need detailed logs to debug and optimize the script , but i do not want see the debug information scroll the screen.
  4. i need a tool to query which updates the offline image need before i patch it .
  5. when using the dism command line tool at a OS with defferent language from the machine where the script was writen, the script gets error

So, my script is to resolve the problems above.

before you using this script ,there are some suggestions to you.

  1. install wsus console before you using the script.
  2. i suggest you using windows server 2012 r2 to do offline patch (when i using windows server 2012(not R2) to offline patch a VHD which os was windows server 2012 r2, the dismhost.exe crash often, after i change to windows server 2012 r2, the crash disapear.
  3. change the WSUSServerName parameter or WsusServerPort parameter to suit your environment, so you no need to input it every time.

Usage: you can use get-help d:\patch-windowsimage.ps1 to get the help too.

     .EXAMPLE
        .\Patch-WindowsImage.ps1 -PatchUsingWSUS -ImagePath D:\foo\win7.vhdx -WsusServerName wsus -WsusServerPort 80
       
        This command will use the folder $scriptFolder\mount to mount the imagePath using imageindex (default =1).then it will scan the wsusServer using the wsusServerName and WsusServerPort.the scan process will get your offline windows image info first.the script will read the regedit of your offline image ,and determine the OSVERSION,OSARC,COMPUTERROLE,and using these values to scan the wsus,and then get
which update is suit for your offlineimage.then it will patch your offline image.

    .EXAMPLE
        .\Patch-WindowsImage.ps1 -PatchUsingWSUS -ImagePath D:\foo\win7.vhdx

        You must need install the wsus console first.This command will  use the folder $scriptFolder\mount to mount the imagePath using imageindex (default =1),then it will scan the wsusServerName(Default=wsus,and you can change it to suit for your environment),WsusServerPort(Default=80) .the scan process will get your offline windows image info first.the script will read the regedit of your offline image ,and determine the OSVERSION,OSARC,COMPUTERROLE,and using these
values to scan the wsus,and then get which update is suit for your offlineimage.then it will patch your offline image.
   
    .EXAMPLE
        .\Patch-WindowsImage.ps1 -QueryImageInfo -ImagePath D:\foo\win7.vhdx

        you can use this command to query the information of your offline image (to query osversion,arch,computerRole)
   
    .EXAMPLE
        .\Patch-WindowsImage.ps1 -QueryImagePatchList -ImagePath D:\foo\win7.vhdx -wsusServerName wsus -wsusServerPort 80

        you can use this command to query the updates your offline image need. which they need ,which has been patched ,cabs count you really need to patch.

    .EXAMPLE
        .\Patch-WindowsImage.ps1 -PatchsFolder d:\patches -ImagePath D:\foo\win7.vhdx

        the command use a local folder which contains update cabs or msu files to patch your offline image