Script to get WSUS server from Local Group Policy and Registry

Posted on 2013-09-04
Medium Priority
Last Modified: 2013-09-05
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!!
Question by:Irrylyn
  • 2
  • 2
LVL 65

Accepted Solution

RobSampson earned 2000 total points
ID: 39465823
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


Author Comment

ID: 39467279
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!

Author Closing Comment

ID: 39467284
Perfect script.
LVL 65

Expert Comment

ID: 39468835
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.



Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Loops Section Overview
Did you know PowerShell can save you time with SaaS platforms? Simply leverage RESTfulAPIs to build your own PowerShell modules. These will kill repetitive tickets and tabs, using the command Invoke-RestMethod. Tune into this webinar to learn how…

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question