How to Assign a Package to a Distribution Point
The following example shows how to assign a distribution point to a package by using the SMS_DistributionPoint
and SMS_SystemResourceList
classes in Configuration Manager. 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
Set up a connection to the SMS Provider.
Create a new distribution point object (this is not an actual distribution point).
Associate the existing package with the new distribution point object.
Query for a single distribution point based on the provided site code and server name.
Use the query results to populate the
ServerNALPath
property of the distribution point object.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)
Const wbemFlagReturnImmediately = 16
Const wbemFlagForwardOnly = 32
Dim distributionPoint
Dim query
Dim listOfResources
Dim resource
' 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
Microsoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
Assembly
adminui.wqlqueryengine
microsoft.configurationmanagement.managementprovider
mscorlib
Robust Programming
For more information about error handling, see About Configuration Manager Errors.
See Also
Software distribution overview
About the site control file
SMS_SCI_Component Server WMI Class
SMS_SystemResourceList Server WMI Class