• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 421
  • Last Modified:

How to enter wsus server name for windows server 2008 through vbscript??

Hi All,

We are manually installing MS patch for windows server 2008.

Is there any way to add WSUS server name through vbscript or any other way as it takes lots of time through group policy??

These are the below steps which we are doing MS Patch for windows server 2008.

1.GOTO RUN-->Start Type MMC
2.GOTO File-->Select Add or Remove Snap-ins.
3. In Add or Remove Snap-ins select Group Policy Object.
 1.png2.jpg4.Click on Finish
5.GOTO Computer Configuration\Administrative Templates\Windows Components\Windows Update, Double Click on Configure Automatic Updates
6.Select ENABLED, and in select “2 – Notify for download and notify for install”. Click OK
7.Double click on “Specify intranet Microsoft update service location”, Under OPTIONS enter the WSUS server name (http://wsusservername.com )


8.Click OK.
9.Once you have clicked on OK, POPUP can be seen for downloading or installing updates. Click on the POPUP and select INSTALL.
10.Also check  in the registry if it is pointing to the correct WSUS server HKML\Software\Policies\Software\Policies\Microsoft\Windows\WindowsUpdate
Else modify to point to the correct WSUS server

11.ELSE, Rt.Click on MY Computer, click on Properties and click on “WINDOWS Update”

Can anyone help me how to enter WSUS server name through vbscript without going Group policy??

Any assistance would be greatly appreciated.
2 Solutions
Hi, Try next script, it does more things, you need to change to your case
Change cstrSUSServerURL  to your WSUS server
'/* Windows Script Host Script: SetWUSServerCN.vbs                                  */
'/*                                                                                 */
'/* Connects the Windows Update service of the current computer to the WSUS server  */
'/* specified by the constant cstrSUSServerURL.                                     */
Option Explicit

Const cstrSUSServerURL = ""

'/* Function: ConfigureWindowsUpdate                                                */
'/*                                                                                 */
'/* Configures the Windows Update service for connecting to the specified WSUS      */
'/* server using the URL specified by the constant cstrSUSServerURL.                */
Function ConfigureWindowsUpdate()

  Dim intReturn, objWSHShell

  '// enable error handling
  On Error Resume Next

  '// create a new instance of the shell object
  Set objWSHShell = WScript.CreateObject("WScript.Shell")

  '// enter the registry keys needed to connect to the SUS Server
  objWSHShell.RegWrite "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\WUServer", cstrSUSServerURL, "REG_SZ"
  objWSHShell.RegWrite "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\WUStatusServer", cstrSUSServerURL, "REG_SZ"
  '// enter the registry keys specifying the update method and options
  objWSHShell.RegWrite "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU\NoAutoRebootWithLoggedOnUsers", 1, "REG_DWORD"
  objWSHShell.RegWrite "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU\UseWUServer", 1, "REG_DWORD"
  objWSHShell.RegWrite "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU\RescheduleWaitTime", 1, "REG_DWORD"
  objWSHShell.RegWrite "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU\NoAutoUpdate", 0, "REG_DWORD"
  objWSHShell.RegWrite "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU\AUOptions", 3, "REG_DWORD"

  '// enter the registry key for specifyig the day and time of day when service checks for updates
  objWSHShell.RegWrite "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU\ScheduledInstallDay", 0, "REG_DWORD"
  objWSHShell.RegWrite "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU\ScheduledInstallTime", 10, "REG_DWORD"

  '// check the overall return status
  If (Err.Number <> 0) Then
    '// an error occured while writing the registry keys, set the completion code to 
    '// error (and leave a respective message in the log file)
    intReturn = intError
    WScript.Echo "(E) Error writing the WUS client configuration entries to the registry (" & Err.Number & ", " & Err.Description & ")."
    '// the function succeeded, set the return status to success 
    intReturn = intSuccess
    WScript.Echo "(S) WUS client configuration successfully written to registry."
  End If

  '// release the resources allocated by the shell object
  Set objWSHShell = Nothing

  '// turn off error handling
  On Error GoTo 0

  '// and terminate the function by returning the respective completion code
  ConfigureWindowsUpdate = intReturn

End Function

'/* Main                                                                            */
Dim intReturn

'// set the initial return status to error
intReturn = intError

'// write a short not about the beginning of the script to the log file
WScript.Echo "(I) Windows Update Service (WUS) configuration started with URL '" & cstrSUSServerURL & "'."

'// enter the registry keys for connecting the windows update service via the WSUS server
intReturn = ConfigureWindowsUpdate()

'// in case the updated succeeded, restart the windows update service in order to activated the settings
If (intReturn <> intSuccess) Then
  '// the configuration failed, terminate the function with error (derived from the previous function)
  WScript.Echo "(F) Windows Update Service (WUS) configuration failed, automatic updates will not work properly."
  '// the configuration has been successfuly, restart the service in order to activate the settings;
  '// stop the service
  intReturn = StopService ("Windows Update")

  '// and start it over again
  intReturn = (intReturn OR StartService ("Windows Update"))

  '// check if an error occured during the restart; in that case write a warning to the log
  If (intReturn <> intSuccess) Then
    '// at least one of the service functions failed; write a warning to the log
    WScript.Echo "(W) Restart of the 'Windows Update' service failed, please check the service status manually."
    '// the restart has been successfull
    WScript.Echo "(S) 'Windows Update' service sucessfully restarted."
  End If

  '// all the important functions succeeded, terminate the function with a success message
  WScript.Echo "(S) Windows Update Service (WUS) configuration terminated successfully."
End If

Open in new window

To clarify your situation, you have a Windows 2008 Server and a number of clients. WSUS will automate the update process, allow yout to delay updates and provide reporting.

The script above would set the WSUS server but not take into account SSL or a different port being used for WSUS.

If you have a domain and WSUS setup on the the server, then you only need to setup a minimum of one Group Policy to configure clients to receive the WSUS server settings. WSUS is best used with Client Targeting, in which case you need more than one Group Policy to for each group of clients you want to target with different settings. E.g. Servers to not automatcially apply updates or restart, clients to apply updates at a certain time and restart.

Why are you creating an MMC console for editing the Group Policy, why not use the Group Policy Management console?

If you do not have a domain but have WSUS setup on the server and need to set the cleint you can do that simply with the following registry fragment that can be tattooed in to the registry which is not recommended by using a batch file with the following command:

REGEDIT /S WSUS-Settings.reg


Windows Registry Editor Version 5.00

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

Featured Post

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now