다음을 통해 공유


구성 할당을 나열하는 방법

다음 코드 예제에서는 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;  
    }  
}  

예제 메서드에는 다음 매개 변수가 있습니다.

매개 변수 형식 설명
- 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 참조하세요.

참고 항목

구성 기준 및 구성 항목 정보
개체 개요관리 코드를 사용하여 Configuration Manager 공급자에 연결하는 방법
WMI를 사용하여 Configuration Manager 공급자에 연결하는 방법
SMS_BaselineAssignment 서버 WMI 클래스