| title | Assign a Package to a Distribution Point |
|---|---|
| description | In Configuration Manager, the following example shows how to assign a distribution point to a package by using the SMS_DistributionPoint and SMS_SystemResourceList classes. |
| ms.date | 09/20/2016 |
| ms.subservice | sdk |
| ms.topic | how-to |
| ms.collection | tier3 |
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.
-
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
ServerNALPathproperty of the distribution point object. -
Save the distribution point object and properties.
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 Subpublic 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 |
|---|---|---|
connectionswbemServices |
- 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. |
The C# example requires:
System
Microsoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
adminui.wqlqueryengine
microsoft.configurationmanagement.managementprovider
mscorlib
For more information about error handling, see About Configuration Manager Errors.
Software distribution overview About the site control file SMS_SCI_Component Server WMI Class SMS_SystemResourceList Server WMI Class