Edit

Share via


How to Configure the WSUS Settings

You configure the Windows Server Update Services (WSUS) component settings, in Configuration Manager, by modifying the site control file. For more information, see Windows Server Update Services.

To configure WSUS settings

  1. Set up a connection to the SMS Provider.

  2. Make a connection to the WSUS Configuration Manager component section of the site control file by using the SMS_SCI_Component class.

  3. Loop through the array of available properties, making changes as needed.

  4. Commit the property changes to the site control file.

Example

The following example method configures various Windows Server Update Services (WSUS) component settings by using the SMS_SCI_Component class to connect to the site control file and change properties.

Note

For more information, see Prepare for software updates management.

For information about calling the sample code, see Calling Configuration Manager Code Snippets.


Sub ConfigureWSUSSettings(swbemServices,         _
                          swbemContext,          _
                          siteCode,              _
                          newDefaultWSUSIISPort, _
                          newSSLDefaultWSUS,     _
                          newDefaultWSUSIISSSLPort)

    ' Load site control file and get the SMS_WSUS_CONFIGURATION_MANAGER component section.
    swbemServices.ExecMethod "SMS_SiteControlFile.Filetype=1,Sitecode=""" & siteCode & """", "Refresh", , , swbemContext

    Query = "SELECT * FROM SMS_SCI_Component " & _
            "WHERE ComponentName = 'SMS_WSUS_CONFIGURATION_MANAGER' " & _
            "AND SiteCode = '" & siteCode & "'"

    Set SCIComponentSet = swbemServices.ExecQuery(Query, ,wbemFlagForwardOnly Or wbemFlagReturnImmediately, swbemContext)

    ' Only one instance is returned from the query.
    For Each SCIComponent In SCIComponentSet

        ' Loop through the array of embedded SMS_EmbeddedProperty instances.
        For Each vProperty In SCIComponent.Props

            ' Display the WSUS server name.
            If vProperty.PropertyName = "DefaultWSUS" Then
                wscript.echo " "
                wscript.echo vProperty.PropertyName & " Server: " & vProperty.Value2
            End If

            ' Setting: DefaultWSUSIISPort.
            If vProperty.PropertyName = "DefaultWSUSIISPort" Then
                wscript.echo " "
                wscript.echo vProperty.PropertyName
                wscript.echo "Current value " &  vProperty.Value

                ' Modify the value.
                vProperty.Value = newDefaultWSUSIISPort
                wscript.echo "New value " & newDefaultWSUSIISPort
            End If

            ' Setting: SSLDefaultWSUS.
            If vProperty.PropertyName = "SSLDefaultWSUS" Then
                wscript.echo " "
                wscript.echo vProperty.PropertyName
                wscript.echo "Current value " &  vProperty.Value

                ' Modify the value.
                vProperty.Value = newSSLDefaultWSUS
                wscript.echo "New value " & newSSLDefaultWSUS
            End If

            ' Setting: DefaultWSUSIISSSLPort.
            If vProperty.PropertyName = "DefaultWSUSIISSSLPort" Then
                wscript.echo " "
                wscript.echo vProperty.PropertyName
                wscript.echo "Current value " &  vProperty.Value

                ' Modify the value.
                vProperty.Value = newDefaultWSUSIISSSLPort
                wscript.echo "New value " & newDefaultWSUSIISSSLPort
            End If

        Next

             ' Update the component in your copy of the site control file. Get the path
             ' to the updated object, which could be used later to retrieve the instance.
             Set SCICompPath = SCIComponent.Put_(wbemChangeFlagUpdateOnly, swbemContext)
    Next

    ' Commit the change to the actual site control file.
    Set InParams = swbemServices.Get("SMS_SiteControlFile").Methods_("CommitSCF").InParameters.SpawnInstance_
    InParams.SiteCode = siteCode
    swbemServices.ExecMethod "SMS_SiteControlFile", "CommitSCF", InParams, , swbemContext

End Sub


public void ConfigureWSUSSettings(WqlConnectionManager connection,
                                    string siteCode,
                                    string SUPServerName,
                                    string newDefaultWSUSIISPort,
                                    string newSSLDefaultWSUS,
                                    string newDefaultWSUSIISSSLPort)
{
    try
    {
        // Connect to SMS_WSUS_CONFIGURATION_MANAGER section of the site control file.
        IResultObject siteDefinition = connection.GetInstance(@"SMS_SCI_Component.FileType=2,ItemType='Component',SiteCode='" + siteCode + "',ItemName='SMS_WSUS_CONFIGURATION_MANAGER|" + SUPServerName + "'");
        foreach (KeyValuePair<string, IResultObject> kvp in siteDefinition.EmbeddedProperties)
        {
            // Temporary copy of the embedded properties.
            Dictionary<string, IResultObject> embeddedProperties = siteDefinition.EmbeddedProperties;

            // Display the WSUS server name.
            if (kvp.Value.PropertyList["PropertyName"] == "DefaultWSUS")
            {
                Console.WriteLine();
                Console.WriteLine(kvp.Value.PropertyList["PropertyName"] + " Server");
                Console.WriteLine("Server name: " + embeddedProperties["DefaultWSUS"]["Value2"].StringValue);
            }

            // Setting: DefaultWSUSIISPort.
            if (kvp.Value.PropertyList["PropertyName"] == "DefaultWSUSIISPort")
            {
                Console.WriteLine();
                Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);
                Console.WriteLine("Current value: " + embeddedProperties["DefaultWSUSIISPort"]["Value"].StringValue);

                // Change the value by using the newDefaultWSUSIISPort value passed that is in.
                embeddedProperties["DefaultWSUSIISPort"]["Value"].StringValue = newDefaultWSUSIISPort;
                Console.WriteLine("New value    : " + newDefaultWSUSIISPort);
            }

            // Setting: SSLDefaultWSUS.
            if (kvp.Value.PropertyList["PropertyName"] == "SSLDefaultWSUS")
            {
                Console.WriteLine();
                Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);
                Console.WriteLine("Current value: " + embeddedProperties["SSLDefaultWSUS"]["Value"].StringValue);

                // Change the value by using the newSSLDefaultWSUS value that is passed in.
                embeddedProperties["SSLDefaultWSUS"]["Value"].StringValue = newSSLDefaultWSUS;
                Console.WriteLine("New value    : " + newSSLDefaultWSUS);
            }

            // Setting: DefaultWSUSIISSSLPort.
            if (kvp.Value.PropertyList["PropertyName"] == "DefaultWSUSIISSSLPort")
            {
                Console.WriteLine();
                Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);
                Console.WriteLine("Current value: " + embeddedProperties["DefaultWSUSIISSSLPort"]["Value"].StringValue);

                // Change the value by using the newDefaultWSUSIISSSLPort value that is passed in.
                embeddedProperties["DefaultWSUSIISSSLPort"]["Value"].StringValue = newDefaultWSUSIISSSLPort;
                Console.WriteLine("New value    : " + newDefaultWSUSIISSSLPort);
            }

            // Store the settings that have changed.
            siteDefinition.EmbeddedProperties = embeddedProperties;
        }

        // Save the settings.
        siteDefinition.Put();

    }
    catch (SmsException ex)
    {
        Console.WriteLine("Failed. Error: " + ex.InnerException.Message);
        throw;
    }
}

The example method has the following parameters:

Parameter Type Description
connection - Managed: WqlConnectionManager
- VBScript: SWbemServices
A valid connection to the SMS Provider.
swbemContext - VBScript: SWbemContext A valid context object. For more information, see How to Add a Configuration Manager Context Qualifier by Using WMI.
siteCode - Managed: String
- VBScript: String
The site code.
SUPServerName - Managed: String
- VBScript: String
The name of the software update point server.
newDefaultWSUSIISPort - Managed: String
- VBScript: String
The new default WSUS Internet Information Services (IIS) port.
newSSLDefaultWSUS - Managed: String
- VBScript: String
Determines whether to use Secure Sockets Layer (SSL).
newDefaultWSUSIISSSLPort - Managed: String
- VBScript: String
Identifies the default WSUS IIS SSL port.

Compiling the Code

This C# example requires:

Namespaces

System

System.Collections.Generic

System.Text

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

adminui.wqlqueryengine

microsoft.configurationmanagement.managementprovider

Robust Programming

For more information about error handling, see About Configuration Manager Errors.

.NET Framework Security

For more information about securing Configuration Manager applications, see Configuration Manager role-based administration.

See Also

About Software Updates Setup and Configuration About the Configuration Manager Site Control File How to Read and Write to the Configuration Manager Site Control File by Using Managed Code How to Read and Write to the Configuration Manager Site Control File by Using WMI SMS_SCI_Component Server WMI Class How to Add a Configuration Manager Context Qualifier by Using WMI