Compartir a través de


How to Assign a Package to a Distribution Point

Applies To: System Center Configuration Manager 2007, System Center Configuration Manager 2007 R2, System Center Configuration Manager 2007 R3, System Center Configuration Manager 2007 SP1, System Center Configuration Manager 2007 SP2

The following example shows how to assign a distribution point to a package by using the SMS_DistributionPoint Server WMI Class and SMS_SystemResourceList Server WMI Class classes in Microsoft System Center Configuration Manager 2007. You only need to assign a distribution point to a package if the package contains source files (PkgSourcePath). The package is not advertised until the program source files have been propagated to a distribution point share. You can use the default distribution point share, or you can specify a share to use. You can also specify more than one distribution point to use to distribute your package source files, although this example does not demonstrate that.

To assign a package to a distribution point

  1. Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.

  2. Create a new distribution point object (this is not an actual distribution point).

  3. Associate the existing package with the new distribution point object.

  4. Query for a single distribution point based on the provided site code and server name.

  5. Use the query results to populate the ServerNALPath property of the distribution point object.

  6. Save the distribution point object and properties.

Example

The following example method assigns a package to a distribution point.

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

Sub SWDAssignPackageToDistributionPoint(connection, existingPackageID, siteCode, serverName)

    ' Create distribution point object (this is not an actual distribution point).
    Set distributionPoint = connection.Get("SMS_DistributionPoint").SpawnInstance_

    ' Associate the existing package with the new distribution point object.
    distributionPoint.PackageID = existingPackageID     

    ' This query selects a single distribution point based on the provided SiteCode and ServerName.
    query = "SELECT * FROM SMS_SystemResourceList WHERE RoleName='SMS Distribution Point' AND SiteCode='" & siteCode & "' AND ServerName='" & serverName & "'"

    Set listOfResources = connection.ExecQuery(query, , wbemFlagForwardOnly Or wbemFlagReturnImmediately)

    ' The query returns a collection that needs to be enumerated (although we should only get one instance back).
    For Each resource In ListOfResources      
        distributionPoint.ServerNALPath = Resource.NALPath
        distributionPoint.SiteCode = Resource.SiteCode        
    Next
    
    ' Save the distribution point instance for the package.
    distributionPoint.Put_ 
    
    ' Display notification text.
    Wscript.Echo "Assigned package: " & distributionPoint.PackageID 

End Sub
public void AssignPackageToDistributionPoint(WqlConnectionManager connection, string existingPackageID, string siteCode, string serverName)
{
    try
    {
        // Create the distribution point object (this is not an actual distribution point).
        IResultObject distributionPoint = connection.CreateInstance("SMS_DistributionPoint");

        // Associate the package with the new distribution point object. 
        distributionPoint["PackageID"].StringValue = existingPackageID;

        // This query selects a single distribution point based on the provided siteCode and serverName.
        string query = "SELECT * FROM SMS_SystemResourceList WHERE RoleName='SMS Distribution Point' AND SiteCode='" + siteCode + "' AND ServerName='" + serverName + "'";

        // 
        IResultObject listOfResources = connection.QueryProcessor.ExecuteQuery(query);
        foreach (IResultObject resource in listOfResources)
        {
            Console.WriteLine(resource["SiteCode"].StringValue);
            distributionPoint["ServerNALPath"].StringValue = resource["NALPath"].StringValue;
            distributionPoint["SiteCode"].StringValue = resource["SiteCode"].StringValue;
        }

        // Save the distribution point object and properties.
        distributionPoint.Put();

        // Output package ID of assigned package.
        Console.WriteLine("Assigned package: " + distributionPoint["PackageID"].StringValue);
    }

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

The example method has the following parameters:

Parameter Type Description

connection

swbemServices

  • Managed: WqlConnectionManager

  • VBScript: SWbemServices

A valid connection to the SMS Provider.

existingPackageID

  • Managed: String

  • VBScript: String

The ID of the existing package.

siteCode

  • Managed: String

  • VBScript: String

The site code.

serverName

  • Managed: String

  • VBScript: String

The name of the server.

Compiling the Code

The C# example requires:

Namespaces

System

System.Collections.Generic

System.ComponentModel

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.

Security

For more information about securing Configuration Manager applications, see Securing Configuration Manager Applications.

See Also

Reference

SMS_DistributionPoint Server WMI Class

Concepts

Configuration Manager Software Distribution
Software Distribution Packages
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
SMS_SystemResourceList Server WMI Class