Cleanup registry from WSUS server, ZTIWindowsupdate.wsf

This is something I thought I posted a long time ago, but here we go.

I logged in to my WSUS Server that I only use when building images and nothing else and found that more than 100 clients had tried to contact it and got the reminder.
I have about 15 test clients perhaps but have only built two images using this WSUS, I have done a lot of testing with Intune management though.

The ZTIWindowsUpdate.wsf script used in MDT and which can be used standalone as well in Configuration Manager to deploy updates either from Windows Update or a WSUS writes the policy registry key for the policy to use a WSUS server and it doesn’t clean it up.

WSUS_2

So that was why all my machines tried to contact my WSUS server.
Normally this would be an issue but it depends on how you will deploy your image and the use of it. A simple vbscript will cleanup the registry keys created by the ZTIWindowsUpdate.Wsf that can be run in the task sequence.

On Error Resume Next
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
strKeyPath = "Software\Policies\Microsoft\Windows\WindowsUpdate"
Set objRegistry = GetObject("winmgmts:\\" & _
strComputer & "\root\default:StdRegProv")
DeleteSubkeys HKEY_LOCAL_MACHINE, strKeypath
Sub DeleteSubkeys(HKEY_LOCAL_MACHINE, strKeyPath)
objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys
If IsArray(arrSubkeys) Then
For Each strSubkey In arrSubkeys
DeleteSubkeys HKEY_LOCAL_MACHINE, strKeyPath & "\" & strSubkey
Next
End If
objRegistry.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath
End Sub

On Error Resume Next

Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
strKeyPath = "Software\Policies\Microsoft\Windows\WindowsUpdate"
Set objRegistry = GetObject("winmgmts:\\" & _
strComputer & "\root\default:StdRegProv")
DeleteSubkeys HKEY_LOCAL_MACHINE, strKeypath
Sub DeleteSubkeys(HKEY_LOCAL_MACHINE, strKeyPath)
objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys
If IsArray(arrSubkeys) Then
For Each strSubkey In arrSubkeys
DeleteSubkeys HKEY_LOCAL_MACHINE, strKeyPath & "\" & strSubkey
Next
End If
objRegistry.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath
End Sub

One Comment

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.