Script to get WSUS server from Local Group Policy and Registry

Environment:  All Windows 7 x64 Enterprise
SCCM 2007 R2 & SUP for updates

Hi experts!!  (aka my favorite people!)

I have a computerlist.txt with about 200 computer names in it.  I would like a script that will check the value of the following two entries and then output it to a file:

In Registry:  HKLM\Software\Policies\Microsoft\Windows\WindowsUpdate  : the Data value for WUServer.

In Local Group Policy:  Computer Configuration\Administrative Templates\Windows Components\Windows Update\Specify Intranet Update Service Location  :  the value of option 'Set the intranet update service for detecting updates'

I would love both to be done, but if it's not possible to get the value from the Local Group Policy, I will be ok with just the registry key.

Thank you!!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi, try this VBS code.



strInput = "computers.txt"
strOutput = "WSUS_Client_Settings.csv"

Const HKEY_LOCAL_MACHINE = &H80000002
strKey = "Software\Policies\Microsoft\Windows\WindowsUpdate"
strWUServerValueName = "WUServer"
strWUStatusServerValueName = "WUStatusServer"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInput = objFSO.OpenTextFile(strInput, 1, False)
Set objOutput = objFSO.CreateTextFile(strOutput, True)
objOutput.WriteLine """Hostname"",""WUServer"",""WUStatusServer"""
While Not objInput.AtEndOfStream
	strComputer = Trim(objInput.ReadLine)
	If strComputer <> "" Then
		If Ping(strComputer) = True Then
			On Error Resume Next
			Set objRegistry = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & strComputer & "\root\default:StdRegProv")
			If Err.Number = 0 Then
				objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKey, strWUServerValueName, strWUServer
				objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKey, strWUStatusServerValueName, strWUStatusServer
				objOutput.WriteLine """" & strComputer & """,""" & strWUServer & """,""" & strWUStatusServer & """"
				objOutput.WriteLine """" & strComputer & """,""<ERROR " &  Err.Number & " - " & Err.Description & ">"",""<ERROR " &  Err.Number & " - " & Err.Description & ">"""
				On Error GoTo 0
			End If
			objOutput.WriteLine """" & strComputer & """,""<OFFLINE>"",""<OFFLINE>"""
		End If
	End If
WScript.Echo "Done"

Function Ping(strComputer)
	Dim objShell, boolCode
	Set objShell = CreateObject("WScript.Shell")
	boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
	If boolCode = 0 Then
		Ping = True
		Ping = False
	End If
End Function

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
IrrylynAuthor Commented:
Rob...  you continue to blow my mind, as always.  Every time I see your name on one of my questions I breath a little easier because I know you hit the nail on the head every single time!  I hope you really love what you do, because you're awesome!

The above vbs worked without a hitch.  No changes/modifications were needed.  Beautiful.  Thank you, this is helping me to verify an issue we've been having and now I can begin figuring out the cause/fix!
IrrylynAuthor Commented:
Perfect script.
Great.  Thanks for the grade.  I do love the things we can do with scripting, which is why I've been using it for more than 8 years now.  It can make life much easier!

Glad it worked for you.


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.