次の方法で共有


構成基準を割り当てる方法

Configuration Managerでは、構成基準をコレクションに割り当てるために、割り当てインスタンスが作成され、必要な値の最小セットが設定され、保存されます。

構成基準を割り当てるには

  1. SMS プロバイダーへの接続を設定します。

  2. SMS_BaselineAssignmentインスタンスを作成します。

  3. インスタンスのプロパティを設定します。

  4. 新しい SMS_BaselineAssignment インスタンスを保存します。

次のコード例は、ベースライン割り当てのインスタンスを作成する方法を示しています。

サンプル コードの呼び出しについては、「Configuration Manager コード スニペットの呼び出し」を参照してください。


Sub DCMCreateAssignment(swbemServices,                     _  
                        baselineID,                        _  
                        applyToSubTargets,                 _  
                        assignmentAction,                  _  
                        assignmentName,                    _  
                        assignmentDescription,             _  
                        desiredConfigType,                 _  
                        distributionPointLocality,         _  
                        evaluationSchedule,                _  
                        logComplianceToWinEvent,           _  
                        notifyUser,                        _  
                        sendDetailedNonComplianceStatus,   _  
                        startTime,                         _  
                        suppressReboot,                    _  
                        targetCollectionID,                _  
                        useGMTTimes)  

' Create new assignment object.  
set newAssignment = swbemServices.Get("SMS_BaselineAssignment").SpawnInstance_()        

' Assign variable values to assignment properties.  
'    //  
'    // The following properties are set by the provider on put():  
'    //     AssignmentID  
'    //     AssignmentUniqueID  
'    //     SourceSite  
'    //     CreationTime  

newAssignment.ApplyToSubTargets = applyToSubTargets   
newAssignment.AssignmentAction = assignmentAction   
newAssignment.AssignmentName = assignmentName   
newAssignment.AssignmentDescription = assignmentDescription   
newAssignment.DesiredConfigType = desiredConfigType   
newAssignment.DPLocality = distributionPointLocality   
newAssignment.EvaluationSchedule = evaluationSchedule   
newAssignment.LogComplianceToWinEvent = logComplianceToWinEvent   
newAssignment.NotifyUser = notifyUser   
newAssignment.SendDetailedNonComplianceStatus = sendDetailedNonComplianceStatus   
newAssignment.StartTime = startTime   
newAssignment.SuppressReboot = suppressReboot   
newAssignment.TargetCollectionID = targetCollectionID   
newAssignment.UseGMTTimes = useGMTTimes   
newAssignment.AssignedCIs = Array(baselineID)   

' Save assignment.  
newAssignment.Put_  

Wscript.Echo " "  
Wscript.Echo "Created new assignment."      

End Sub  


public void DCMCreateAssignment(WqlConnectionManager connection,  
                                bool applyToSubTargets,  
                                int assignmentAction,  
                                string assignmentName,  
                                string assignmentDescription,  
                                string desiredConfigType,  
                                int distributionPointLocality,  
                                string evaluationSchedule,  
                                bool logComplianceToWinEvent,  
                                bool notifyUser,  
                                bool sendDetailedNonComplianceStatus,  
                                string startTime,  
                                int suppressReboot,  
                                string targetCollectionID,  
                                bool useGMTTimes,  
                                int baselineID)  
{  

    // Set required variables.   
    // Set AssignedCIs like array with a known baseline id (this is the initial creation of the assignment, so no existing values).  
    int[] arrayBaselineNumbers = new int[] { baselineID };  

    try  
    {  
        // Create new assignment object.  
        IResultObject newAssignment = connection.CreateInstance("SMS_BaselineAssignment");  

        // Assign variable values to assignment properties.  
        //  
        // The following properties are set by the provider on put():  
        //     AssignmentID  
        //     AssignmentUniqueID  
        //     SourceSite  
        //     CreationTime  
        newAssignment["ApplyToSubTargets"].BooleanValue = applyToSubTargets;  
        newAssignment["AssignmentAction"].IntegerValue = assignmentAction;  
        newAssignment["AssignmentName"].StringValue = assignmentName;  
        newAssignment["AssignmentDescription"].StringValue = assignmentDescription;  
        newAssignment["DesiredConfigType"].StringValue = desiredConfigType;  
        newAssignment["DPLocality"].IntegerValue = distributionPointLocality;  
        newAssignment["EvaluationSchedule"].StringValue = evaluationSchedule;  
        newAssignment["LogComplianceToWinEvent"].BooleanValue = logComplianceToWinEvent;  
        newAssignment["NotifyUser"].BooleanValue = notifyUser;  
        newAssignment["SendDetailedNonComplianceStatus"].BooleanValue = sendDetailedNonComplianceStatus;  
        newAssignment["StartTime"].StringValue = startTime;  
        newAssignment["SuppressReboot"].IntegerValue = suppressReboot;  
        newAssignment["TargetCollectionID"].StringValue = targetCollectionID;  
        newAssignment["AssignedCIs"].IntegerArrayValue = arrayBaselineNumbers;  
        newAssignment["UseGMTTimes"].BooleanValue = useGMTTimes;  

        // Save assignment object.  
        newAssignment.Put();  
    }  
    catch (SmsException ex)  
    {  
        Console.WriteLine("Failed to create new assignment." + "\\n" + ex.Message);  
        throw;  
    }  

    Console.WriteLine("Created new assignment.");  

}  

このメソッドの例には、次のパラメーターがあります。

パラメーター 説明
- connection
- swbemServices
-管理: WqlConnectionManager
- VBScript: SWbemServices
SMS プロバイダーへの有効な接続。
applyToSubTargets -管理: Boolean
-Vbscript: Boolean
true を使用して、構成項目の割り当てをサブコレクションに適用します。
assignmentAction -管理: Integer
-Vbscript: Integer
構成項目の割り当てに関連付けられているアクション。
assignmentName -管理: String
-Vbscript: String
assignmentName
assignmentDescription -管理: String
-Vbscript: String
ローカル割り当て名。
desiredConfigType -管理: String
-Vbscript: String
構成項目の種類。
distributionPointLocality -管理: Integer
-Vbscript: Integer
配布ポイントの局所性に従って、クライアントが配布ポイントを取得する方法を決定するフラグ。
evaluationSchedule -管理: String
-Vbscript: String
割り当て評価スケジュール。
logComplianceToWinEvent -管理: Boolean
-Vbscript: Boolean
true コンプライアンスの状態を Windows イベント ログに記録します。
notifyUser -管理: Boolean
-Vbscript: Boolean
true をクリックして、構成項目が使用可能になったときにユーザーに通知します。
sendDetailedNonComplianceStatus -管理: Boolean
-Vbscript: Boolean
true をクリックして、コンプライアンス違反の詳細な状態メッセージを送信します。
startTime -管理: String
-Vbscript: String
構成項目の割り当てが最初に提供された日時。
suppressReboot -管理: Integer
-Vbscript: Integer
構成項目が適用された後に再起動が保留中の場合、クライアントがコンピューターを再起動しないかどうかを示す値。
targetCollectionID -管理: String
-Vbscript: String
割り当てが対象となるコレクションの識別子。
useGMTTimes -管理: Boolean
-Vbscript: Boolean
true 時刻とスケジュールが世界協定時刻 (UTC) にある場合。
baselineID - マネージド: Integer 配列
- VBScript: Integer 配列
割り当ての対象となる構成項目の ID の配列。

コードのコンパイル

名前空間

System

System.Collections.Generic

System.ComponentModel

Microsoft。ConfigurationManagement.ManagementProvider

Microsoft。ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

adminui.wqlqueryengine

microsoft.configurationmanagement.managementprovider

堅牢なプログラミング

エラー処理の詳細については、「Configuration Manager エラーについて」を参照してください。

.NET Framework のセキュリティ

Configuration Manager アプリケーションのセキュリティ保護の詳細については、「ロールベースの管理Configuration Manager」を参照してください。

関連項目

構成基準と構成項目について
オブジェクトの概要マネージド コードを使用してConfiguration Manager プロバイダーに接続する方法
WMI を使用してConfiguration Manager プロバイダーに接続する方法
サーバー WMI クラスのSMS_BaselineAssignment