共用方式為


如何將套件指派給發佈點

下列範例示範如何使用 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;
    }
}

範例方法具有下列參數:

參數 Type 描述
connection

swbemServices
-管理: WqlConnectionManager
- VBScript: SWbemServices
SMS 提供者的有效連線。
existingPackageID -管理: String
- VBScript: String
現有封裝的標識碼。
siteCode -管理: String
- VBScript: String
月臺碼。
serverName -管理: String
- VBScript: String
伺服器的名稱。

正在編譯程式碼

C# 範例需要:

命名空間

系統

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

組件

adminui.wqlqueryengine

microsoft.configurationmanagement.managementprovider

mscorlib

健全的程式設計

如需錯誤處理的詳細資訊,請參閱關於 Configuration Manager 錯誤

另請參閱

軟體發佈概觀關於伺服器WMI 類別SMS_SCI_Component伺服器 WMI 類別SMS_SystemResourceList月臺控制檔案