DSC のトラブルシューティング
適用対象: Windows PowerShell 4.0、Windows PowerShell 5.1
この記事では、一般的なエラー のトラブルシューティング方法を示します。
WinRM の依存関係
Windows PowerShell Desired State Configuration (DSC) は、WinRM に依存します。 Windows Server 2008 R2 および Windows 7 では、WinRM は既定では有効になっていません。 WinRM を有効にするには、Windows PowerShell 管理者特権セッションで Set-WSManQuickConfig
を実行します。
Get-DscConfigurationStatus の使用
Get-DscConfigurationStatus コマンドレットは、ターゲット ノードから構成状態に関する情報を取得します。 このコマンドは、構成の実行が成功したかどうかに関する高レベルの情報を含むリッチ オブジェクトを返します。 オブジェクトを調べ、次に挙げるような構成の実行に関する詳細を知ることができます:
- 失敗したすべてのリソース。
- 再起動を要求したリソース。
- 構成の実行時に設定を Meta-Configuration します。
次のパラメーター セットは、最後の構成の実行状況に関する情報を返します。
Get-DscConfigurationStatus [-CimSession <CimSession[]>]
[-ThrottleLimit <int>]
[-AsJob]
[<CommonParameters>]
次のパラメーター セットは、すべての構成実行の状態情報を返します。
Get-DscConfigurationStatus -All
[-CimSession <CimSession[]>]
[-ThrottleLimit <int>]
[-AsJob]
[<CommonParameters>]
例
PS C:\> $Status = Get-DscConfigurationStatus
PS C:\> $Status
Status StartDate Type Mode RebootRequested NumberOfResources
------ --------- ---- ---- --------------- -----------------
Failure 11/24/2015 3:44:56 Consistency Push True 36
PS C:\> $Status.ResourcesNotInDesiredState
ConfigurationName : MyService
DependsOn :
ModuleName : PSDesiredStateConfiguration
ModuleVersion : 1.1
PsDscRunAsCredential :
ResourceID : [File]ServiceDll
SourceInfo : c:\git\CustomerService\Configs\MyCustomService.ps1::5::34::File
DurationInSeconds : 0.19
Error : SourcePath must be accessible for current configuration. The related file/directory is:
\\Server93\Shared\contosoApp.dll. The related ResourceID is [File]ServiceDll
FinalState :
InDesiredState : False
InitialState :
InstanceName : ServiceDll
RebootRequested : False
ResourceName : File
StartDate : 11/24/2015 3:44:56
PSComputerName :
スクリプトが実行されない:DSC ログを使用したスクリプト エラーの診断
すべての Windows ソフトウェアと同様に、DSC は、イベント ビューアーで確認できるログにエラーとイベントを記録します。 これらのログを調べることは、特定の操作が失敗した理由や、今後エラーを防止する方法を理解するために役立ちます。 作成時にエラーの追跡を容易にするには、DSC ログ リソースを使用して、DSC Analytic イベント ログで構成の進行状況を追跡します。
DSC イベント ログの場所
イベント ビューアーでは、DSC イベントは Applications and Services Logs/Microsoft/Windows/Desired State Configuration にあります。
対応する PowerShell コマンドレット Get-WinEvent を実行して、イベント ログを表示できます。
PS C:\> Get-WinEvent -LogName "Microsoft-Windows-Dsc/Operational"
ProviderName: Microsoft-Windows-DSC
TimeCreated Id LevelDisplayName Message
----------- -- ---------------- -------
11/17/2014 10:27:23 PM 4102 Information Job {02C38626-D95A-47F1-9DA2-C1D44A7128E7} :
DSC のプライマリ ログ名は Microsoft-Windows-DSC>> です (簡潔にするために、Windows の下の他のログ名はここに表示されません)。 プライマリ名がチャネル名に追加され、完全なログ名が作成されます。
DSC エンジンは、主に操作ログ、分析ログ、デバッグ ログという 3 種類のログに書き込みます。 分析ログとデバッグ ログは既定では有効になっていないので、イベント ビューアーで有効にする必要があります。 これを行うには、次の手順を実行します。
次のいずれかの方法でイベント ビューアーを開きます。
- Windows PowerShellでの入力
Show-EventLog
- [スタート] ボタンを選択し、[コントロール パネル]、[管理ツール] の順に選択し、[イベント ビューアーします。
- Windows PowerShellでの入力
イベント ビューアーの [表示 ] メニューで、[ 分析ログとデバッグ ログの表示] を選択します。
分析チャネルのログ名は で
Microsoft-Windows-Dsc/Analytic
、デバッグ チャネルは ですMicrosoft-Windows-Dsc/Debug
。
次の例に示すように、wevtutil ユーティリティを使用してログを有効にすることもできます。
wevtutil.exe set-log "Microsoft-Windows-Dsc/Analytic" /q:true /e:true
または、次の例に示すように、PowerShell と .NET を使用してログを有効にしてください。
$logName = 'Microsoft-Windows-Dsc/Analytic'
$log = New-Object System.Diagnostics.Eventing.Reader.EventLogConfiguration $logName
$log.IsEnabled = $true
$log.SaveChanges()
DSC ログに含まれる内容
DSC ログは、メッセージの重要度に基づいて 3 つの異なるログ チャネルに記録されます。 DSC の操作ログにはすべてのエラー メッセージが含まれており、問題を特定するのに役立ちます。 分析ログには大量のイベントがあり、エラーが発生した場所を特定できます。 このチャネルには、出力された詳細メッセージも含まれます。 デバッグ ログには、エラーがどのように発生したかを理解するのに役立つログが含まれています。 DSC イベント メッセージは、DSC 操作を一意に表すジョブ ID で始まります。 次の例では、操作 DSC ログに記録された最初のイベントからメッセージの取得を試みます。
PS C:\> $AllDscOpEvents = Get-WinEvent -LogName "Microsoft-Windows-Dsc/Operational"
PS C:\> $FirstOperationalEvent = $AllDscOpEvents[0]
PS C:\> $FirstOperationalEvent.Message
Job {02C38626-D95A-47F1-9DA2-C1D44A7128E7} :
Consistency engine was run successfully.
DSC は、ユーザーが 1 つの DSC ジョブからイベントを収集できるようにする構造でイベントをログに記録します。 構造は次のとおりです。
Job ID : <Guid>
<Event Message>
1 つの DSC 操作からのイベントの収集
DSC イベント ログには、各種の DSC 操作によって生成されたイベントが含まれています。 ただし、通常は特定の操作の詳細に関心があります。 すべての DSC ログは、DSC 操作ごとに一意のジョブ ID プロパティでグループ化できます。 ジョブ ID は、すべての DSC イベントの最初のプロパティ値として表示されます。 次の手順では、グループ化された配列構造にすべてのイベントを蓄積する方法について説明します。
<##########################################################################
Step 1 : Enable analytic and debug DSC channels (Operational channel is enabled by default)
###########################################################################>
wevtutil.exe set-log "Microsoft-Windows-Dsc/Analytic" /q:true /e:true
wevtutil.exe set-log "Microsoft-Windows-Dsc/Debug" /q:True /e:true
<##########################################################################
Step 2 : Perform the required DSC operation (Below is an example, you could run any DSC operation instead)
###########################################################################>
Get-DscLocalConfigurationManager
<##########################################################################
Step 3 : Collect all DSC Logs, from the Analytic, Debug and Operational channels
###########################################################################>
$DscEvents=[System.Array](Get-WinEvent "Microsoft-Windows-Dsc/Operational") `
+ [System.Array](Get-WinEvent "Microsoft-Windows-Dsc/Analytic" -Oldest) `
+ [System.Array](Get-WinEvent "Microsoft-Windows-Dsc/Debug" -Oldest)
<##########################################################################
Step 4 : Group all logs based on the job ID
###########################################################################>
$SeparateDscOperations = $DscEvents | Group {$_.Properties[0].value}
この変数 $SeparateDscOperations
には、ジョブ ID でグループ化されたログが含まれます。 この変数の各配列要素は、さまざまな DSC 操作によって記録されたイベントのグループを表しており、ログの詳細にアクセスできるようになっています。
PS C:\> $SeparateDscOperations
Count Name Group
----- ---- -----
48 {1A776B6A-5BAC-11E3-BF... {System.Diagnostics.Eventing.Reader.EventLogRecord, System.Diagnostics....
40 {E557E999-5BA8-11E3-BF... {System.Diagnostics.Eventing.Reader.EventLogRecord, System.Diagnostics....
PS C:\> $SeparateDscOperations[0].Group
ProviderName: Microsoft-Windows-DSC
TimeCreated Id LevelDisplayName Message
----------- -- ---------------- -------
12/2/2013 3:47:29 PM 4115 Information Job {1A776B6A-5BAC-11E3-BF41-00155D553612} : ...
12/2/2013 3:47:29 PM 4198 Information Job {1A776B6A-5BAC-11E3-BF41-00155D553612} : ...
12/2/2013 3:47:29 PM 4114 Information Job {1A776B6A-5BAC-11E3-BF41-00155D553612} : ...
12/2/2013 3:47:29 PM 4102 Information Job {1A776B6A-5BAC-11E3-BF41-00155D553612} : ...
12/2/2013 3:47:29 PM 4098 Warning Job {1A776B6A-5BAC-11E3-BF41-00155D553612} : ...
12/2/2013 3:47:29 PM 4098 Warning Job {1A776B6A-5BAC-11E3-BF41-00155D553612} : ...
12/2/2013 3:47:29 PM 4176 Information Job {1A776B6A-5BAC-11E3-BF41-00155D553612} : ...
12/2/2013 3:47:29 PM 4182 Information Job {1A776B6A-5BAC-11E3-BF41-00155D553612} : ...
12/2/2013 3:47:29 PM 4182 Information Job {1A776B6A-5BAC-11E3-BF41-00155D553612} : ...
12/2/2013 3:47:29 PM 4182 Information Job {1A776B6A-5BAC-11E3-BF41-00155D553612} : ...
12/2/2013 3:47:29 PM 4182 Information Job {1A776B6A-5BAC-11E3-BF41-00155D553612} : ...
12/2/2013 3:47:29 PM 4182 Information Job {1A776B6A-5BAC-11E3-BF41-00155D553612} : ...
12/2/2013 3:47:29 PM 4182 Information Job {1A776B6A-5BAC-11E3-BF41-00155D553612} : ...
12/2/2013 3:47:29 PM 4182 Information Job {1A776B6A-5BAC-11E3-BF41-00155D553612} : ...
12/2/2013 3:47:29 PM 4182 Information Job {1A776B6A-5BAC-11E3-BF41-00155D553612} : ...
Where-Object を使用して変数 $SeparateDscOperations
内のデータを抽出できます。
DSC のトラブルシューティングのためにデータを抽出する 5 つのシナリオを次に示します。
1:操作エラー
すべてのイベントには重大度レベルがあります。 この情報は、エラー イベントを特定するのに役立ちます。
PS C:\> $SeparateDscOperations | Where-Object {$_.Group.LevelDisplayName -contains "Error"}
Count Name Group
----- ---- -----
38 {5BCA8BE7-5BB6-11E3-BF... {System.Diagnostics.Eventing.Reader.EventLogRecord, System.Diagnostics....
2:過去 30 分間に実行された操作の詳細
それぞれの Windows イベントのプロパティである TimeCreated
は、イベントが作成された時刻を示します。 このプロパティを特定の日付/時刻オブジェクトと比較すると、すべてのイベントをフィルター処理するのに役立ちます。
PS C:\> $DateLatest = (Get-Date).AddMinutes(-30)
PS C:\> $SeparateDscOperations | Where-Object {$_.Group.TimeCreated -gt $DateLatest}
Count Name Group
----- ---- -----
1 {6CEC5B09-5BB0-11E3-BF... {System.Diagnostics.Eventing.Reader.EventLogRecord}
3:最後の操作からのメッセージ
最後の操作は、配列グループ $SeparateDscOperations
の最初のインデックスに格納されています。
グループのメッセージに対してインデックス 0 のクエリを実行すると、最後の操作に関するすべてのメッセージが返されます。
PS C:\> $SeparateDscOperations[0].Group.Message
Job {5BCA8BE7-5BB6-11E3-BF41-00155D553612} :
Running consistency engine.
Job {1A776B6A-5BAC-11E3-BF41-00155D553612} :
Configuration is sent from computer NULL by user sid S-1-5-18.
Job {1A776B6A-5BAC-11E3-BF41-00155D553612} :
Displaying messages from built-in DSC resources:
WMI channel 1
ResourceID:
Message : [INCH-VM]: [] Starting consistency engine.
Job {1A776B6A-5BAC-11E3-BF41-00155D553612} :
Displaying messages from built-in DSC resources:
WMI channel 1
ResourceID:
Message : [INCH-VM]: [] Consistency check completed.
4:最近失敗した操作について記録されたエラー メッセージ
$SeparateDscOperations[0].Group
には、最新の操作の一連のイベントがあります。 レベル表示名に基づいてイベントをフィルター処理するには、Where-Object
コマンドレットを実行します。 結果は $myFailedEvent
変数に格納され、これをより細かく分析してイベント メッセージを取得できます。
PS C:\> $myFailedEvent = ($SeparateDscOperations[0].Group |
Where-Object {$_.LevelDisplayName -eq "Error"})
PS C:\> $myFailedEvent.Message
Job {5BCA8BE7-5BB6-11E3-BF41-00155D553612} :
DSC Engine Error :
Error Message Current configuration does not exist. Execute Start-DscConfiguration command with
-Path parameter to specify a configuration file and create a current configuration first.
Error Code : 1
5:特定のジョブ ID 用に生成されたすべてのイベント
$SeparateDscOperations
はグループの配列であり、それぞれが一意のジョブ ID として名前を持ちます。 Where-Object
コマンドレットを実行すると、特定のジョブ ID を持つイベントのグループを抽出できます。
PS C:\> ($SeparateDscOperations | Where-Object {$_.Name -eq $jobX} ).Group
ProviderName: Microsoft-Windows-DSC
TimeCreated Id LevelDisplayName Message
----------- -- ---------------- -------
12/2/2013 4:33:24 PM 4102 Information Job {847A5619-5BB2-11E3-BF41-00155D553612} : ...
12/2/2013 4:33:24 PM 4168 Information Job {847A5619-5BB2-11E3-BF41-00155D553612} : ...
12/2/2013 4:33:24 PM 4146 Information Job {847A5619-5BB2-11E3-BF41-00155D553612} : ...
12/2/2013 4:33:24 PM 4120 Information Job {847A5619-5BB2-11E3-BF41-00155D553612} : ...
xDscDiagnostics を使用した DSC ログの分析
xDscDiagnostics は、コンピューター上の DSC 障害の分析に役立つ複数の関数で構成される PowerShell モジュールです。 これらの関数は、過去の DSC 操作からのすべてのローカル イベント、またはリモート コンピューター上の DSC イベントを識別するのに役立ちます。 ここで、DSC 操作という用語は、その開始から終了までの 1 つの一意の DSC 実行を定義します。 たとえば、Test-DscConfiguration
は独立した DSC 操作です。 同様に、DSC の他のすべてのコマンドレット (や Start-DscConfiguration
などGet-DscConfiguration
) は、個別の DSC 操作として識別できます。 診断関数の詳細については、「xDscDiagnostics」を参照してください。
DSC 操作の詳細の取得
関数 Get-xDscOperation
を使用すると、1 つ以上のコンピューターで実行される DSC 操作の結果を見つけることができます。 この関数は、各 DSC 操作によって生成されるイベントのコレクションを持つ オブジェクトを返します。 たとえば、次の出力では、3 つのコマンドが実行されました。 1 つ目のコマンドは成功し、他の 2 つのコマンドは失敗しました。 の Get-xDscOperation
出力は、これらの結果をまとめたものです。
PS C:\DiagnosticsTest> Get-xDscOperation
ComputerName SequenceId TimeCreated Result JobID AllEvents
------------ ---------- ----------- ------ ----- ---------
SRV1 1 6/23/2016 9:37:52 AM Failure 9701aadf-395e-11e6-9165-00155d390509 {@{Message=; TimeC...
SRV1 2 6/23/2016 9:36:54 AM Failure 7e8e2d6e-395c-11e6-9165-00155d390509 {@{Message=; TimeC...
SRV1 3 6/23/2016 9:36:54 AM Success af72c6aa-3960-11e6-9165-00155d390509 {@{Message=Operati...
Newest パラメーターを指定すると、最新の操作についてのみ結果を取得できます。
PS C:\DiagnosticsTest> Get-xDscOperation -Newest 5
ComputerName SequenceId TimeCreated Result JobID AllEvents
------------ ---------- ----------- ------ ----- ---------
SRV1 1 6/23/2016 4:36:54 PM Success {@{Message=; TimeC...
SRV1 2 6/23/2016 4:36:54 PM Success 5c06402b-399b-11e6-9165-00155d390509 {@{Message=Operati...
SRV1 3 6/23/2016 4:36:54 PM Success {@{Message=; TimeC...
SRV1 4 6/23/2016 4:36:54 PM Success 5c06402a-399b-11e6-9165-00155d390509 {@{Message=Operati...
SRV1 5 6/23/2016 4:36:51 PM Success {@{Message=; TimeC...
DSC イベントの詳細の取得
Trace-xDscOperation
コマンドレットは、イベント、そのイベントの種類、および特定の DSC 操作から生成されたメッセージ出力のコレクションが含まれているオブジェクトを返します。 通常、 を使用して Get-xDscOperation
いずれかの操作でエラーが見つかると、その操作をトレースして、エラーの原因となったイベントを見つけます。
SequenceID
パラメーターを使用して特定のコンピューターの特定の操作に対するイベントを取得します。
たとえば、SequenceID
に 9 を指定すると、Trace-xDscOperation
は最後の操作から 9 番目の DSC 操作のトレースを取得します。
PS C:\DiagnosticsTest> Trace-xDscOperation -SequenceID 9
ComputerName EventType TimeCreated Message
------------ --------- ----------- -------
SRV1 OPERATIONAL 6/24/2016 10:51:52 AM Operation Consistency Check or Pull started by user sid S-1-5-20 from computer NULL.
SRV1 OPERATIONAL 6/24/2016 10:51:52 AM Running consistency engine.
SRV1 OPERATIONAL 6/24/2016 10:51:52 AM The local configuration manager is updating the PSModulePath to WindowsPowerShell\Modules;C:\Prog...
SRV1 OPERATIONAL 6/24/2016 10:51:53 AM Resource execution sequence :: [WindowsFeature]DSCServiceFeature, [xDSCWebService]PSDSCPullServer.
SRV1 OPERATIONAL 6/24/2016 10:51:54 AM Consistency engine was run successfully.
SRV1 OPERATIONAL 6/24/2016 10:51:54 AM Job runs under the following LCM setting. ...
SRV1 OPERATIONAL 6/24/2016 10:51:54 AM Operation Consistency Check or Pull completed successfully.
割り当てられた GUID を特定の DSC 操作に渡すと (Get-xDscOperation
コマンドレットが返したときに)、その DSC 操作のイベントの詳細を取得できます。
PS C:\DiagnosticsTest> Trace-xDscOperation -JobID 9e0bfb6b-3a3a-11e6-9165-00155d390509
ComputerName EventType TimeCreated Message
------------ --------- ----------- -------
SRV1 OPERATIONAL 6/24/2016 11:36:56 AM Operation Consistency Check or Pull started by user sid S-1-5-20 from computer NULL.
SRV1 ANALYTIC 6/24/2016 11:36:56 AM Deleting file from C:\Windows\System32\Configuration\DSCEngineCache.mof
SRV1 OPERATIONAL 6/24/2016 11:36:56 AM Running consistency engine.
SRV1 VERBOSE 6/24/2016 11:36:56 AM [SRV1]: [] Starting consistency engine.
SRV1 ANALYTIC 6/24/2016 11:36:56 AM Applying configuration from C:\Windows\System32\Configuration\Current.mof.
SRV1 ANALYTIC 6/24/2016 11:36:56 AM Parsing the configuration to apply.
SRV1 OPERATIONAL 6/24/2016 11:36:56 AM Resource execution sequence :: [WindowsFeature]DSCServiceFeature, [xDSCWebService]PSDSCPullServer.
SRV1 VERBOSE 6/24/2016 11:36:56 AM [SRV1]: LCM: [ Start Resource ] [[WindowsFeature]DSCServiceFeature]
SRV1 ANALYTIC 6/24/2016 11:36:56 AM Executing operations for PS DSC resource MSFT_RoleResource with resource name [WindowsFeature]DSC...
SRV1 VERBOSE 6/24/2016 11:36:56 AM [SRV1]: LCM: [ Start Test ] [[WindowsFeature]DSCServiceFeature]
SRV1 VERBOSE 6/24/2016 11:36:56 AM [SRV1]: [[WindowsFeature]DSCServiceFeature] The operation 'Get...
SRV1 VERBOSE 6/24/2016 11:36:56 AM [SRV1]: [[WindowsFeature]DSCServiceFeature] The operation 'Get...
SRV1 VERBOSE 6/24/2016 11:36:56 AM [SRV1]: LCM: [ End Test ] [[WindowsFeature]DSCServiceFeature] True in 0.3130 sec...
SRV1 VERBOSE 6/24/2016 11:36:56 AM [SRV1]: LCM: [ End Resource ] [[WindowsFeature]DSCServiceFeature]
SRV1 VERBOSE 6/24/2016 11:36:56 AM [SRV1]: LCM: [ Start Resource ] [[xDSCWebService]PSDSCPullServer]
SRV1 ANALYTIC 6/24/2016 11:36:56 AM Executing operations for PS DSC resource MSFT_xDSCWebService with resource name [xDSCWebService]P...
SRV1 VERBOSE 6/24/2016 11:36:56 AM [SRV1]: LCM: [ Start Test ] [[xDSCWebService]PSDSCPullServer]
SRV1 VERBOSE 6/24/2016 11:36:56 AM [SRV1]: [[xDSCWebService]PSDSCPullServer] Check Ensure
SRV1 VERBOSE 6/24/2016 11:36:56 AM [SRV1]: [[xDSCWebService]PSDSCPullServer] Check Port
SRV1 VERBOSE 6/24/2016 11:36:56 AM [SRV1]: [[xDSCWebService]PSDSCPullServer] Check Physical Path ...
SRV1 VERBOSE 6/24/2016 11:36:56 AM [SRV1]: [[xDSCWebService]PSDSCPullServer] Check State
SRV1 VERBOSE 6/24/2016 11:36:56 AM [SRV1]: [[xDSCWebService]PSDSCPullServer] Get Full Path for We...
SRV1 VERBOSE 6/24/2016 11:36:56 AM [SRV1]: LCM: [ End Test ] [[xDSCWebService]PSDSCPullServer] True in 0.0160 seconds.
SRV1 VERBOSE 6/24/2016 11:36:56 AM [SRV1]: LCM: [ End Resource ] [[xDSCWebService]PSDSCPullServer]
SRV1 VERBOSE 6/24/2016 11:36:56 AM [SRV1]: [] Consistency check completed.
SRV1 ANALYTIC 6/24/2016 11:36:56 AM Deleting file from C:\Windows\System32\Configuration\DSCEngineCache.mof
SRV1 OPERATIONAL 6/24/2016 11:36:56 AM Consistency engine was run successfully.
SRV1 OPERATIONAL 6/24/2016 11:36:56 AM Job runs under the following LCM setting. ...
SRV1 OPERATIONAL 6/24/2016 11:36:56 AM Operation Consistency Check or Pull completed successfully.
SRV1 ANALYTIC 6/24/2016 11:36:56 AM Deleting file from C:\Windows\System32\Configuration\DSCEngineCache.mof
分析ログ、デバッグ ログ、運用ログからイベントを集計するため Trace-xDscOperation
、これらのログを有効にするように求めるメッセージが表示されることに注意してください。
また、Trace-xDscOperation
の出力を変数に保存して、イベントに関する情報を収集することもできます。 次のコマンドを使用すると、特定の DSC 操作のすべてのイベントを表示できます。
PS C:\DiagnosticsTest> $Trace = Trace-xDscOperation -SequenceID 4
PS C:\DiagnosticsTest> $Trace.Event
これにより、次の出力のように、コマンドレットと Get-WinEvent
同じ結果が表示されます。
ProviderName: Microsoft-Windows-DSC
TimeCreated Id LevelDisplayName Message
----------- -- ---------------- -------
6/23/2016 1:36:53 AM 4312 Information The DscTimer is running LCM method PerformRequiredConfigurationChecks with the flag set to 5.
6/23/2016 1:36:53 AM 4343 Information The DscTimer has successfully run LCM method PerformRequiredConfigurationChecks with flag 5.
6/23/2016 2:07:00 AM 4312 Information The DscTimer is running LCM method PerformRequiredConfigurationChecks with the flag set to 5.
6/23/2016 2:07:01 AM 4343 Information The DscTimer has successfully run LCM method PerformRequiredConfigurationChecks with flag 5.
6/23/2016 2:36:55 AM 4312 Information The DscTimer is running LCM method PerformRequiredConfigurationChecks with the flag set to 5.
6/23/2016 2:36:56 AM 4343 Information The DscTimer has successfully run LCM method PerformRequiredConfigurationChecks with flag 5.
6/23/2016 3:06:55 AM 4312 Information The DscTimer is running LCM method PerformRequiredConfigurationChecks with the flag set to 5.
6/23/2016 3:06:55 AM 4343 Information The DscTimer has successfully run LCM method PerformRequiredConfigurationChecks with flag 5.
6/23/2016 3:36:55 AM 4312 Information The DscTimer is running LCM method PerformRequiredConfigurationChecks with the flag set to 5.
6/23/2016 3:36:55 AM 4343 Information The DscTimer has successfully run LCM method PerformRequiredConfigurationChecks with flag 5.
6/23/2016 4:06:53 AM 4312 Information The DscTimer is running LCM method PerformRequiredConfigurationChecks with the flag set to 5.
6/23/2016 4:06:53 AM 4343 Information The DscTimer has successfully run LCM method PerformRequiredConfigurationChecks with flag 5.
6/23/2016 4:36:52 AM 4312 Information The DscTimer is running LCM method PerformRequiredConfigurationChecks with the flag set to 5.
6/23/2016 4:36:53 AM 4343 Information The DscTimer has successfully run LCM method PerformRequiredConfigurationChecks with flag 5.
6/23/2016 5:06:52 AM 4312 Information The DscTimer is running LCM method PerformRequiredConfigurationChecks with the flag set to 5.
6/23/2016 5:06:53 AM 4343 Information The DscTimer has successfully run LCM method PerformRequiredConfigurationChecks with flag 5.
6/23/2016 5:36:54 AM 4312 Information The DscTimer is running LCM method PerformRequiredConfigurationChecks with the flag set to 5.
6/23/2016 5:36:54 AM 4343 Information The DscTimer has successfully run LCM method PerformRequiredConfigurationChecks with flag 5.
6/23/2016 6:06:52 AM 4312 Information The DscTimer is running LCM method PerformRequiredConfigurationChecks with the flag set to 5.
6/23/2016 6:06:53 AM 4343 Information The DscTimer has successfully run LCM method PerformRequiredConfigurationChecks with flag 5.
6/23/2016 6:36:56 AM 4312 Information The DscTimer is running LCM method PerformRequiredConfigurationChecks with the flag set to 5.
6/23/2016 6:36:57 AM 4343 Information The DscTimer has successfully run LCM method PerformRequiredConfigurationChecks with flag 5.
6/23/2016 7:06:52 AM 4312 Information The DscTimer is running LCM method PerformRequiredConfigurationChecks with the flag set to 5.
6/23/2016 7:06:53 AM 4343 Information The DscTimer has successfully run LCM method PerformRequiredConfigurationChecks with flag 5.
6/23/2016 7:36:53 AM 4312 Information The DscTimer is running LCM method PerformRequiredConfigurationChecks with the flag set to 5.
6/23/2016 7:36:54 AM 4343 Information The DscTimer has successfully run LCM method PerformRequiredConfigurationChecks with flag 5.
6/23/2016 8:06:54 AM 4312 Information The DscTimer is running LCM method PerformRequiredConfigurationChecks with the flag set to 5.
まず、Get-xDscOperation
を使用して、コンピューターでの DSC 構成実行のうち、最新のいくつかを一覧表示すると理想的です。 その後、 SequenceID または JobID を に指定して、バックグラウンドで Trace-xDscOperation
何が行ったのかを検出することで、任意の 1 つの操作を調べることができます。
リモート コンピューターのイベントの取得
Trace-xDscOperation
コマンドレットの ComputerName
パラメーターを使用して、リモート コンピューターのイベントの詳細を取得します。 これを行う前に、ファイアウォール ルールを作成してリモート コンピューターでのリモート管理を許可する必要があります。
New-NetFirewallRule -Name "Service RemoteAdmin" -DisplayName "Remote" -Action Allow
これで、Trace-xDscOperation
への呼び出しでそのコンピューターを指定できます。
Trace-xDscOperation -ComputerName SRV2 -Credential Get-Credential -SequenceID 5
ComputerName EventType TimeCreated Message
------------ --------- ----------- -------
SRV2 OPERATIONAL 6/24/2016 11:36:56 AM Operation Consistency Check or Pull started by user sid S-1-5-20 f...
SRV2 ANALYTIC 6/24/2016 11:36:56 AM Deleting file from C:\Windows\System32\Configuration\DSCEngineCach...
SRV2 OPERATIONAL 6/24/2016 11:36:56 AM Running consistency engine.
SRV2 VERBOSE 6/24/2016 11:36:56 AM [SRV2]: [] Starting consistency...
SRV2 ANALYTIC 6/24/2016 11:36:56 AM Applying configuration from C:\Windows\System32\Configuration\Curr...
SRV2 ANALYTIC 6/24/2016 11:36:56 AM Parsing the configuration to apply.
SRV2 OPERATIONAL 6/24/2016 11:36:56 AM Resource execution sequence :: [WindowsFeature]DSCServiceFeature,...
SRV2 VERBOSE 6/24/2016 11:36:56 AM [SRV2]: LCM: [ Start Resource ] [[WindowsFeature]DSCSer...
SRV2 ANALYTIC 6/24/2016 11:36:56 AM Executing operations for PS DSC resource MSFT_RoleResource with re...
SRV2 VERBOSE 6/24/2016 11:36:56 AM [SRV2]: LCM: [ Start Test ] [[WindowsFeature]DSCSer...
SRV2 VERBOSE 6/24/2016 11:36:56 AM [SRV2]: [[WindowsFeature]DSCSer...
SRV2 VERBOSE 6/24/2016 11:36:56 AM [SRV2]: [[WindowsFeature]DSCSer...
SRV2 VERBOSE 6/24/2016 11:36:56 AM [SRV2]: LCM: [ End Test ] [[WindowsFeature]DSCSer...
SRV2 VERBOSE 6/24/2016 11:36:56 AM [SRV2]: LCM: [ End Resource ] [[WindowsFeature]DSCSer...
SRV2 VERBOSE 6/24/2016 11:36:56 AM [SRV2]: LCM: [ Start Resource ] [[xDSCWebService]PSDSCP...
SRV2 ANALYTIC 6/24/2016 11:36:56 AM Executing operations for PS DSC resource MSFT_xDSCWebService with ...
SRV2 VERBOSE 6/24/2016 11:36:56 AM [SRV2]: LCM: [ Start Test ] [[xDSCWebService]PSDSCP...
SRV2 VERBOSE 6/24/2016 11:36:56 AM [SRV2]: [[xDSCWebService]PSDSCP...
SRV2 VERBOSE 6/24/2016 11:36:56 AM [SRV2]: [[xDSCWebService]PSDSCP...
SRV2 VERBOSE 6/24/2016 11:36:56 AM [SRV2]: [[xDSCWebService]PSDSCP...
SRV2 VERBOSE 6/24/2016 11:36:56 AM [SRV2]: [[xDSCWebService]PSDSCP...
SRV2 VERBOSE 6/24/2016 11:36:56 AM [SRV2]: [[xDSCWebService]PSDSCP...
SRV2 VERBOSE 6/24/2016 11:36:56 AM [SRV2]: LCM: [ End Test ] [[xDSCWebService]PSDSCP...
SRV2 VERBOSE 6/24/2016 11:36:56 AM [SRV2]: LCM: [ End Resource ] [[xDSCWebService]PSDSCP...
SRV2 VERBOSE 6/24/2016 11:36:56 AM [SRV2]: [] Consistency check co...
SRV2 ANALYTIC 6/24/2016 11:36:56 AM Deleting file from C:\Windows\System32\Configuration\DSCEngineCach...
SRV2 OPERATIONAL 6/24/2016 11:36:56 AM Consistency engine was run successfully.
SRV2 OPERATIONAL 6/24/2016 11:36:56 AM Job runs under the following LCM setting. ...
SRV2 OPERATIONAL 6/24/2016 11:36:56 AM Operation Consistency Check or Pull completed successfully.
SRV2 ANALYTIC 6/24/2016 11:36:56 AM Deleting file from C:\Windows\System32\Configuration\DSCEngineCach...
リソースが更新されない:キャッシュをリセットする方法
DSC エンジンは、効率化のために、PowerShell モジュールとして実装されているリソースをキャッシュします。 ただし、これは、リソースを作成し、同時にテストするときに問題が発生する可能性があります。これは、DSC がプロセスを再起動するまでキャッシュされたバージョンを読み込むためです。 新しいバージョンが読み込まれるようにする唯一の方法は、DSC エンジンをホストしているプロセスを明示的に強制終了することです。
同様に、カスタム リソースを追加および変更した後に を実行 Start-DscConfiguration
すると、コンピューターが再起動しない限り、または再起動するまで変更が実行されないことがあります。 これは、DSC は WMI プロバイダー ホスト プロセス (WmiPrvSE
) で実行され、通常は WmiPrvSE の多くのインスタンスが一度に実行されるためです。 再起動すると、ホスト プロセスが再起動され、キャッシュがクリアされます。
コンピューターを再起動することなく、構成を正常にリサイクルし、キャッシュをクリアするには、ホスト プロセスを停止してから再起動する必要があります。 これはインスタンス単位で行うことができます。これにより、プロセスを特定し、停止し、再起動します。 また、以下に示すように、DebugMode
を使用して PowerShell DSC リソースを再読み込みすることもできます。
DSC エンジンをホストしているプロセスを識別するには、DSC エンジンをホストしている の WmiPrvSE
プロセス ID を一覧表示します。 次に、プロバイダーを更新するには、次のコマンドを WmiPrvSE
使用してプロセスを停止し、もう一度実行 Start-DscConfiguration
します。
###
### find the process that is hosting the DSC engine
###
$CimParameters = @{
ClassName = 'Msft_Providers'
Filter = "provider='dsctimer' OR provider='dsccore'"
}
$dscProcessID = Get-CimInstance @CimParameters |
Select-Object -ExpandProperty HostProcessIdentifier
###
### Stop the process
###
Get-Process -Id $dscProcessID | Stop-Process
DebugMode の使用
ホスト プロセスの再起動時に DebugMode
を使用して常にキャッシュをクリアするように、DSC ローカル構成マネージャー (LCM) を構成できます。 に $true
設定すると、エンジンは常に PowerShell DSC リソースを再読み込みします。 リソースの書き込みが完了したら、 に $false
設定し直すと、エンジンはモジュールをキャッシュする動作に戻ります。
次は、DebugMode
がどのようにキャッシュを自動的に更新できるかを示すデモです。 まず、既定の構成を見てみましょう。
Get-DscLocalConfigurationManager
AllowModuleOverwrite : False
CertificateID :
ConfigurationID :
ConfigurationMode : ApplyAndMonitor
ConfigurationModeFrequencyMins : 30
Credential :
DebugMode : {None}
DownloadManagerCustomData :
DownloadManagerName :
LocalConfigurationManagerState : Ready
RebootNodeIfNeeded : False
RefreshFrequencyMins : 15
RefreshMode : PUSH
PSComputerName :
が None
であることがわかりますDebugMode
。
DebugMode
のデモを設定するには、次の PowerShell リソースを使用します。
function Get-TargetResource {
param (
[Parameter(Mandatory)] $onlyProperty
)
$Path = "$env:SystemDrive\OutputFromTestProviderDebugMode.txt"
return @{
onlyProperty = Get-Content -Path $Path
}
}
function Set-TargetResource {
param (
[Parameter(Mandatory)] $onlyProperty
)
"1" | Out-File -PSPath "$env:SystemDrive\OutputFromTestProviderDebugMode.txt"
}
function Test-TargetResource {
param (
[Parameter(Mandatory)]
$onlyProperty
)
return $false
}
次に、 という TestProviderDebugMode
構成を作成します。
Configuration ConfigTestDebugMode
{
Import-DscResource -Name TestProviderDebugMode
Node localhost
{
TestProviderDebugMode test
{
onlyProperty = "blah"
}
}
}
ConfigTestDebugMode
ファイル $env:SystemDrive\OutputFromTestProviderDebugMode.txt
の内容は です 1
。
ここで、次のスクリプトを使用してプロバイダー コードを更新します。
$newResourceOutput = Get-Random -Minimum 5 -Maximum 30
$OutputPath = "C:\Program Files\WindowsPowerShell\Modules\MyPowerShellModules\DSCResources\TestProviderDebugMode\TestProviderDebugMode.psm1"
$content = @"
function Get-TargetResource {
param (
[Parameter(Mandatory)] `$onlyProperty
)
`$Path = "$env:SystemDrive\OutputFromTestProviderDebugMode.txt"
return @{
onlyProperty = Get-Content -Path $Path
}
}
function Set-TargetResource {
param (
[Parameter(Mandatory)] `$onlyProperty
)
"$newResourceOutput" | Out-File -PSPath C:\OutputFromTestProviderDebugMode.txt
}
function Test-TargetResource {
param (
[Parameter(Mandatory)] `$onlyProperty
)
return `$false
}
"@ | Out-File -FilePath $OutputPath
このスクリプトは乱数を生成し、プロバイダー コードを更新します。 DebugMode
が false に設定されている場合、ファイル $env:SystemDrive\OutputFromTestProviderDebugMode.txt
の内容は変更されません。
次に、構成スクリプトで を にForceModuleImport
設定DebugMode
します。
LocalConfigurationManager
{
DebugMode = "ForceModuleImport"
}
スクリプトをもう一度実行すると、ファイルの内容が毎回異なることがあります。 を実行Get-DscConfiguration
してチェックできます。 次のスニペットは、さらに 2 つの実行の結果を示しています。 スクリプトを実行すると、結果が異なる場合があります。
PS C:\> Get-DscConfiguration -CimSession (New-CimSession localhost)
onlyProperty PSComputerName
------------ --------------
20 localhost
PS C:\> Get-DscConfiguration -CimSession (New-CimSession localhost)
onlyProperty PSComputerName
------------ --------------
14 localhost
Windows プル サーバーに登録すると、DSC から "予期しない応答コード InternalServerError" が返されます。
メタ構成をサーバーに適用して Windows プル サーバーのインスタンスに登録すると、次のエラーが発生する可能性があります。
Registration of the Dsc Agent with the server https://<serverfqdn>:8080/PSDSCPullServer.svc failed. The underlying error is: The attempt to register Dsc Agent with AgentId <ID> with the server
https://<serverfqdn>:8080/PSDSCPullServer.svc/Nodes(AgentId='<ID>') returned unexpected response code InternalServerError. .
+ CategoryInfo : InvalidResult: (root/Microsoft/...gurationManager:String) [], CimException
+ FullyQualifiedErrorId : RegisterDscAgentUnsuccessful,Microsoft.PowerShell.DesiredStateConfiguration.Commands.RegisterDscAgentCommand
+ PSComputerName : <computername>
これは、トラフィックの暗号化にサーバーで使用される証明書に、URL を解決するためにノードで使用される DNS 名とは異なる共通名 (CN) がある場合に発生する可能性があります。 正しい名前の証明書を使用するように Windows プルサーバーのインスタンスを更新します。
DSC 構成の適用後に Sysprep を実行するとエラーが発生する
DSC 構成を適用した後に Sysprep を実行して Windows Server を一般化しようとすると、次のエラーが発生する可能性があります。
SYSPRP LaunchDll:Failure occurred while executing 'DscCore.dll,SysPrep_Cleanup', returned error code 0x2
Windows PowerShell Desired State Configurationを使用してサーバーを構成した後にサーバーを一般化することは、サポートされているシナリオではありません。 代わりに、Windows セットアップの Specialize フェーズが完了した後で、構成を Windows に適用します。
参照
概念
その他のリソース
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示