如何将包分配到分发点

以下示例演示如何使用 SMS_DistributionPoint Configuration Manager 中的 和 SMS_SystemResourceList 类将分发点分配给包。 仅当包包含源文件 (PkgSourcePath) 时,才需要将分发点分配给包。 在程序源文件传播到分发点共享之前,不会播发包。 可以使用默认分发点共享,也可以指定要使用的共享。 还可以指定多个分发点以用于分发包源文件,尽管此示例未对此进行演示。

将包分配到分发点

  1. 设置与 SMS 提供程序的连接。

  2. 创建新的分发点对象, (这不是实际分发点) 。

  3. 将现有包与新的分发点对象相关联。

  4. 根据提供的站点代码和服务器名称查询单个分发点。

  5. 使用查询结果填充 ServerNALPath 分发点对象的 属性。

  6. 保存分发点对象和属性。

示例

以下示例方法将包分配给分发点。

有关调用示例代码的信息,请参阅调用Configuration Manager代码片段


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;
    }
}

示例方法具有以下参数:

参数 类型 说明
connection

swbemServices
-管理: WqlConnectionManager
- VBScript: SWbemServices
与 SMS 提供程序的有效连接。
existingPackageID -管理: String
- VBScript: String
现有包的 ID。
siteCode -管理: String
- VBScript: String
站点代码。
serverName -管理: String
- VBScript: String
服务器的名称。

编译代码

C# 示例需要:

命名空间

系统警报

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

adminui.wqlqueryengine

microsoft.configurationmanagement.managementprovider

mscorlib

可靠编程

有关错误处理的详细信息,请参阅关于Configuration Manager错误

另请参阅

软件分发概述关于站点控制文件SMS_SCI_Component服务器 WMI 类SMS_SystemResourceList服务器 WMI 类