共用方式為


如何列出組態指派

下列程式代碼範例示範如何列出目前組態基準指派,以及 Configuration Manager 中每個指派的特定屬性集。

列出設定指派

  1. 設定與SMS提供者的連線。

  2. 查詢所有實例 SMS_BaselineAssignment

  3. 迴圈查看可用設定基準指派的陣列,列出每個設定基準指派和特定屬性。

範例

下列範例方法示範如何列出目前組態基準指派,以及 Configuration Manager 中每個指派的特定屬性集。

如需呼叫範例程式代碼的相關信息,請參閱呼叫 Configuration Manager 代碼段


Sub DCMAssignments_ListProperties(swbemServices)  

    On Error Resume Next  

    Dim queryBaselineAssignmentResults  
    Dim assignment  

    ' Query assignments.  
    Set queryBaselineAssignmentResults = swbemServices.ExecQuery("Select * From SMS_BaselineAssignment", , 0)  

    If Err.Number<>0 Then  
        Wscript.Echo "Couldn't get assignments."  
        Exit Sub  
    End If  

    On Error Goto 0  

    ' List assignments and various assignment's properties.  
    For Each assignment In queryBaselineAssignmentResults  
        Wscript.Echo ""  
        Wscript.Echo "Listing Assignment Properties for Assignment ID: " & assignment.AssignmentID  
        Wscript.Echo "Listing Assignment Properties for Assignment Description: " & assignment.AssignmentDescription  
        Wscript.Echo "-------------------------------------------------------------------------------"  
        Wscript.Echo "ApplyToSubTargets: " & assignment.ApplyToSubTargets  
        Wscript.Echo "AssignmentAction:  " & assignment.AssignmentAction  
        Wscript.Echo "AssignmentID: " & assignment.AssignmentID  
        Wscript.Echo "AssignmentName: " & assignment.AssignmentName  
        Wscript.Echo "AssignmentDescription: " & assignment.AssignmentDescription  
        Wscript.Echo "AssignmentUniqueID: " & assignment.AssignmentUniqueID  
        Wscript.Echo "Collection: " & assignment.TargetCollectionID  
        Wscript.Echo "CreationTime: " & assignment.CreationTime  
        Wscript.Echo "DesiredConfigType: " & assignment.DesiredConfigType  
        Wscript.Echo "DPLocality: " & assignment.DPLocality  
        Wscript.Echo "EvaluationSchedule: " & assignment.EvaluationSchedule  
        Wscript.Echo "LogComplianceToWinEvent: " & assignment.LogComplianceToWinEvent  
        Wscript.Echo "NotifyUser: " & assignment.NotifyUser  
        Wscript.Echo "SendDetailedNonComplianceStatus: " & assignment.SendDetailedNonComplianceStatus  
        Wscript.Echo "SourceSite: " & assignment.SourceSite  
        Wscript.Echo "StartTime: " & assignment.StartTime  
        Wscript.Echo "SuppressReboot: " & assignment.SuppressReboot  
        Wscript.Echo "UseGMTTimes: " & assignment.UseGMTTimes  
        Wscript.Echo "==============================================================================="  
    Next  

    If queryBaselineAssignmentResults.Count = 0 Then  
        Wscript.Echo "      no query results"  
    End If  

    set queryBaselineAssignmentResults = Nothing  

End Sub  


public void DCMAssignments_ListProperties(WqlConnectionManager connection)  
{  

    IResultObject baselineAssignments = connection.QueryProcessor.ExecuteQuery("SELECT * FROM SMS_BaselineAssignment");  

    try  
    {  
        foreach (IResultObject assignment in baselineAssignments)  
        {  
            Console.WriteLine("Listing Assignment Properties for Assignment ID: " + assignment["AssignmentID"].StringValue);  
            Console.WriteLine("Listing Assignment Properties for Assignment Description: " + assignment["AssignmentDescription"].StringValue);  
            Console.WriteLine("--------------------------------------------------------------------------------");  
            Console.WriteLine("ApplyToSubTargets: " + assignment["ApplyToSubTargets"].BooleanValue);  
            Console.WriteLine("AssignmentAction:  " + assignment["AssignmentAction"].IntegerValue);  
            Console.WriteLine("AssignmentID: " + assignment["AssignmentID"].StringValue);  
            Console.WriteLine("AssignmentName: " + assignment["AssignmentName"].StringValue);  
            Console.WriteLine("AssignmentDescription: " + assignment["AssignmentDescription"].StringValue);  
            Console.WriteLine("AssignmentUniqueID: " + assignment["AssignmentUniqueID"].StringValue);  
            Console.WriteLine("Collection: " + assignment["TargetCollectionID"].StringValue);  
            Console.WriteLine("CreationTime: " + assignment["CreationTime"].StringValue);  
            Console.WriteLine("DesiredConfigType: " + assignment["DesiredConfigType"].StringValue);  
            Console.WriteLine("DPLocality: " + assignment["DPLocality"].IntegerValue);  
            Console.WriteLine("EvaluationSchedule: " + assignment["EvaluationSchedule"].StringValue);  
            Console.WriteLine("LogComplianceToWinEvent: " + assignment["LogComplianceToWinEvent"].BooleanValue);  
            Console.WriteLine("NotifyUser: " + assignment["NotifyUser"].BooleanValue);  
            Console.WriteLine("SendDetailedNonComplianceStatus: " + assignment["SendDetailedNonComplianceStatus"].BooleanValue);  
            Console.WriteLine("SourceSite: " + assignment["SourceSite"].StringValue);  
            Console.WriteLine("StartTime: " + assignment["StartTime"].StringValue);  
            Console.WriteLine("SuppressReboot: " + assignment["SuppressReboot"].IntegerValue);  
            Console.WriteLine("UseGMTTimes: " + assignment["UseGMTTimes"].BooleanValue);  

            // Process the array.  
            int[] arrayofAssignedCIs = assignment["AssignedCIs"].IntegerArrayValue;  
            Console.Write("Assigned baseline ID(s): ");  
            foreach (int i in arrayofAssignedCIs)  
            {  
                Console.Write(i + " ");  
            }  

            Console.WriteLine();  

            // NULL BY DEFAULT (on a generic assignment created through the user interface).  
            //  
            //Console.WriteLine("EnforcementDeadline: " + assignment["EnforcementDeadline"].StringValue);  
            //Console.WriteLine("ExpirationTime: " + assignment["ExpirationTime"].StringValue);  
            //Console.WriteLine("NonComplianceCriticality: " + assignment["NonComplianceCriticality"].IntegerValue);  
            //Console.WriteLine("OverrideServiceWindows: " + assignment["OverrideServiceWindows"].BooleanValue);  
            //Console.WriteLine("RebootOutsideOfServiceWindows: " + assignment["RebootOutsideOfServiceWindows"].BooleanValue);  
            //Console.WriteLine("WoLEnabled: " + assignment["WoLEnabled"].BooleanValue);  

            Console.WriteLine("================================================================================");  

        }  

    }  
    catch (SmsException ex)  
    {  
        Console.WriteLine("Failed to list assignment properties. Error: " + ex.Message);  
        throw;  
    }  
}  

範例方法具有下列參數:

參數 Type 描述
- connection
- swbemServices
-管理: WqlConnectionManager
- VBScript: SWbemServices
SMS 提供者的有效連線。

正在編譯程式碼

命名空間

系統

System.Collections.Generic

System.ComponentModel

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

組件

adminui.wqlqueryengine

microsoft.configurationmanagement.managementprovider

健全的程式設計

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

.NET Framework 安全性

如需保護 Configuration Manager 應用程式的詳細資訊,請參閱 Configuration Manager 角色型系統管理

另請參閱

關於設定基準和設定專案
物件概觀如何使用 Managed 程式代碼連線到 Configuration Manager 提供者
如何使用 WMI 連線到 Configuration Manager 提供者
SMS_BaselineAssignment伺服器 WMI 類別