Felsöka DSC

Gäller för: Windows PowerShell 4.0, Windows PowerShell 5.1

Den här artikeln innehåller felsökningsinstruktioner för vanliga fel.

WinRM-beroende

Windows PowerShell Desired State Configuration (DSC) är beroende av WinRM. WinRM är inte aktiverat som standard på Windows Server 2008 R2 och Windows 7. Kör Set-WSManQuickConfig, i en Windows PowerShell upphöjd session, för att aktivera WinRM.

Använda Get-DscConfigurationStatus

Cmdleten Get-DscConfigurationStatus hämtar information om konfigurationsstatus från en målnod. Kommandot returnerar ett omfattande objekt som innehåller information på hög nivå om huruvida konfigurationskörningen lyckades eller inte. Du kan gräva i objektet för att identifiera information om konfigurationskörningen, till exempel:

  • Varje resurs som misslyckades.
  • Alla resurser som begärde en omstart.
  • Meta-Configuration inställningar när konfigurationen körs.

Följande parameteruppsättning returnerar statusinformationen för den senaste konfigurationskörningen:

Get-DscConfigurationStatus [-CimSession <CimSession[]>]
                           [-ThrottleLimit <int>]
                           [-AsJob]
                           [<CommonParameters>]

Följande parameteruppsättning returnerar statusinformationen för varje konfigurationskörning:

Get-DscConfigurationStatus -All
                           [-CimSession <CimSession[]>]
                           [-ThrottleLimit <int>]
                           [-AsJob]
                           [<CommonParameters>]

Exempel

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        :

Mitt skript körs inte: Använda DSC-loggar för att diagnostisera skriptfel

Precis som alla Windows-program registrerar DSC fel och händelser i loggar som är tillgängliga för granskning i Loggboken. Genom att undersöka dessa loggar kan du förstå varför en viss åtgärd misslyckades och hur du kan förhindra fel i framtiden. Om du vill göra spårningsfel enklare när du skapar använder du DSC-loggresursen för att spåra förloppet för konfigurationen i DSC-analyshändelseloggen.

Var finns DSC-händelseloggar?

I Loggboken finns DSC-händelser i: Program- och tjänstloggar/Microsoft/Windows/Desired State Configuration

Du kan köra motsvarande PowerShell-cmdlet, Get-WinEvent, för att visa händelseloggarna:

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:s primära loggnamn är Microsoft-Windows-DSC>> (andra loggnamn under Windows visas inte här för korthet). Det primära namnet läggs till i kanalnamnet för att skapa det fullständiga loggnamnet.

DSC-motorn skriver huvudsakligen in i tre typer av loggar: driftloggar, analysloggar och felsökningsloggar. Eftersom analys- och felsökningsloggarna inte är aktiverade som standard bör du aktivera dem i Loggboken. Gör så här:

  1. Öppna Loggboken genom att antingen:

    • Show-EventLog Skriva in Windows PowerShell
    • Välj knappen Start, Kontrollpanelen, sedan Administrationsverktyg och sedan Loggboken.
  2. På menyn Visa i Loggboken väljer du Visa analys- och felsökningsloggar.

    Loggnamnet för analyskanalen är Microsoft-Windows-Dsc/Analyticoch felsökningskanalen är Microsoft-Windows-Dsc/Debug.

Du kan också använda wevtutil-verktyget för att aktivera loggarna, som du ser i följande exempel.

wevtutil.exe set-log "Microsoft-Windows-Dsc/Analytic" /q:true /e:true

Du kan också använda PowerShell och .NET för att aktivera loggarna enligt följande exempel:

$logName = 'Microsoft-Windows-Dsc/Analytic'
$log = New-Object System.Diagnostics.Eventing.Reader.EventLogConfiguration $logName
$log.IsEnabled = $true
$log.SaveChanges()

Vad innehåller DSC-loggar?

DSC loggar till tre olika loggkanaler baserat på meddelandets betydelse. Driftloggen i DSC innehåller alla felmeddelanden och är användbar för att identifiera ett problem. Analysloggen har en högre mängd händelser och kan identifiera var fel inträffade. Den här kanalen innehåller även alla utgivna utförliga meddelanden. Felsökningsloggen har loggar som kan hjälpa dig att förstå hur felen inträffade. DSC-händelsemeddelanden börjar med ett jobb-ID som unikt representerar en DSC-åtgärd. Följande exempel försöker hämta meddelandet från den första händelsen som loggas in i den operativa DSC-loggen.

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 loggar händelser med en struktur som gör det möjligt för användaren att samla in händelser från ett DSC-jobb. Strukturen är följande:

Job ID : <Guid>
<Event Message>

Samla in händelser från en enda DSC-åtgärd

DSC-händelseloggar innehåller händelser som genereras av olika DSC-åtgärder. Vanligtvis handlar det dock om information om en specifik åtgärd. Alla DSC-loggar kan grupperas efter den jobb-ID-egenskap som är unik för varje DSC-åtgärd. Jobb-ID:t visas som det första egenskapsvärdet i alla DSC-händelser. Följande steg förklarar hur du ackumulerar alla händelser i en grupperad matrisstruktur.

<##########################################################################
 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}

Här innehåller variabeln $SeparateDscOperations loggar grupperade efter jobb-ID:t. Varje matriselement i den här variabeln representerar en grupp händelser som loggats av en annan DSC-åtgärd, vilket ger åtkomst till mer information om loggarna.

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} : ...

Du kan extrahera data i variabeln $SeparateDscOperations med Where-Object. Följande är fem scenarier där du kanske vill extrahera data för felsökning av DSC:

1: Driftfel

Alla händelser har allvarlighetsgrad. Den här informationen är användbar för att identifiera felhändelserna:

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: Information om åtgärder som körts under den senaste halvtimmen

TimeCreated, en egenskap för varje Windows-händelse, anger när händelsen skapades. Det är användbart att jämföra den här egenskapen med ett visst datum/tid-objekt för att filtrera alla händelser:

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: Meddelanden från den senaste åtgärden

Den senaste åtgärden lagras i det första indexet för matrisgruppen $SeparateDscOperations. Om du frågar efter gruppens meddelanden för index 0 returneras alla meddelanden för den senaste åtgärden:

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: Felmeddelanden som loggats för de senaste misslyckade åtgärderna

$SeparateDscOperations[0].Group har en uppsättning händelser för den senaste åtgärden. Kör cmdleten Where-Object för att filtrera händelserna baserat på deras visningsnamn på nivån. Resultaten lagras i variabeln $myFailedEvent , som kan dissekeras ytterligare för att hämta händelsemeddelandet:

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: Alla händelser som genereras för ett visst jobb-ID.

$SeparateDscOperations är en matris med grupper som var och en har namnet som unikt jobb-ID. Genom att köra cmdleten Where-Object kan du extrahera de grupper av händelser som har ett visst jobb-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} : ...

Använda xDscDiagnostics för att analysera DSC-loggar

xDscDiagnostics är en PowerShell-modul som består av flera funktioner som kan hjälpa dig att analysera DSC-fel på datorn. Dessa funktioner kan hjälpa dig att identifiera alla lokala händelser från tidigare DSC-åtgärder eller DSC-händelser på fjärrdatorer. Här definierar termen DSC-åtgärd en enda unik DSC-körning från början till slut. Det skulle till exempel Test-DscConfiguration vara en separat DSC-åtgärd. På samma sätt kan alla andra cmdletar i DSC, till exempel Get-DscConfiguration och Start-DscConfiguration, identifieras som separata DSC-åtgärder. Mer information om diagnostikfunktionerna finns i xDscDiagnostics.

Få information om DSC-åtgärder

Med Get-xDscOperation funktionen kan du hitta resultatet av de DSC-åtgärder som körs på en eller flera datorer. Funktionen returnerar ett objekt som har en samling händelser som genereras av varje DSC-åtgärd. I följande utdata kördes till exempel tre kommandon. Den första passerade och de andra två misslyckades. Resultatet av Get-xDscOperation sammanfattar dessa resultat.

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...

Du kan bara få resultat för de senaste åtgärderna genom att ange parametern 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...

Hämta information om DSC-händelser

Cmdleten Trace-xDscOperation returnerar ett objekt som innehåller en samling händelser, deras händelsetyper och de meddelandeutdata som genereras från en viss DSC-åtgärd. När du hittar ett fel i någon av åtgärderna med hjälp Get-xDscOperationav spårar du vanligtvis åtgärden för att hitta de händelser som orsakade ett fel.

Använd parametern SequenceID för att hämta händelserna för en specifik åtgärd för en specifik dator. Om du till exempel anger en SequenceID av 9 Trace-xDscOperation hämtar du spårningen för DSC-åtgärden som var den 9:e från den senaste åtgärden:

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.

Skicka DET GUID som tilldelats till en specifik DSC-åtgärd (som returneras av cmdleten Get-xDscOperation ) för att hämta händelseinformationen för DSC-åtgärden:

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

Observera att eftersom Trace-xDscOperation aggregerar händelser från analys-, felsöknings- och driftloggarna uppmanas du att aktivera dessa loggar.

Alternativt kan du samla in information om händelserna genom att spara utdata Trace-xDscOperation från i en variabel. Du kan använda följande kommandon för att visa alla händelser för en viss DSC-åtgärd.

PS C:\DiagnosticsTest> $Trace = Trace-xDscOperation -SequenceID 4

PS C:\DiagnosticsTest> $Trace.Event

Detta visar samma resultat som cmdleten Get-WinEvent , till exempel i följande utdata:

   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.

Helst skulle du först använda Get-xDscOperation för att lista ut de senaste DSC-konfigurationskörningarna på dina datorer. Därefter kan du undersöka en enskild åtgärd genom att ange dess SequenceID eller JobID med Trace-xDscOperation för att identifiera vad den gjorde i bakgrunden.

Hämta händelser för en fjärrdator

Använd parametern ComputerName för cmdleten Trace-xDscOperation för att hämta händelseinformationen på en fjärrdator. Innan du kan göra detta måste du skapa en brandväggsregel som tillåter fjärradministration på fjärrdatorn:

New-NetFirewallRule -Name "Service RemoteAdmin" -DisplayName "Remote" -Action Allow

Nu kan du ange datorn i anropet till 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...

Mina resurser uppdateras inte: Så här återställer du cacheminnet

DSC-motorn cachelagrar resurser som implementerats som en PowerShell-modul i effektivitetssyfte. Detta kan dock orsaka problem när du redigerar en resurs och testar den samtidigt eftersom DSC läser in den cachelagrade versionen tills processen startas om. Det enda sättet att få DSC att läsa in den nyare versionen är att uttryckligen avsluta processen som är värd för DSC-motorn.

När du kör Start-DscConfiguration, när du har lagt till och ändrat en anpassad resurs, kan ändringen inte köras om inte datorn startas om eller tills den startas om. Detta beror på att DSC körs i WMI-providerns värdprocess (WmiPrvSE), och vanligtvis finns det många instanser av WmiPrvSE som körs samtidigt. När du startar om startar värdprocessen om och rensar cacheminnet.

Om du vill återvinna konfigurationen och rensa cachen utan omstart måste du stoppa och sedan starta om värdprocessen. Detta kan ske per instans, där du identifierar processen, stoppar den och startar om den. Eller så kan du använda DebugMode, som visas nedan, för att läsa in PowerShell DSC-resursen igen.

Om du vill identifiera processen som är värd för DSC-motorn listar du process-ID WmiPrvSE:t för , som är värd för DSC-motorn. Uppdatera sedan providern genom att stoppa WmiPrvSE processen med hjälp av kommandona nedan och sedan köra Start-DscConfiguration igen.

###
### 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

Använda DebugMode

Du kan konfigurera DSC Local Configuration Manager (LCM) för att DebugMode alltid rensa cacheminnet när värdprocessen startas om. När den är inställd $truepå gör den att motorn alltid läser in PowerShell DSC-resursen igen. När du är klar med att skriva resursen kan du ställa in den igen $false och motorn återgår till dess beteende att cachelagra modulerna.

Följande är en demonstration som visar hur DebugMode cacheminnet kan uppdateras automatiskt. Först ska vi titta på standardkonfigurationen:

Get-DscLocalConfigurationManager
AllowModuleOverwrite           : False
CertificateID                  :
ConfigurationID                :
ConfigurationMode              : ApplyAndMonitor
ConfigurationModeFrequencyMins : 30
Credential                     :
DebugMode                      : {None}
DownloadManagerCustomData      :
DownloadManagerName            :
LocalConfigurationManagerState : Ready
RebootNodeIfNeeded             : False
RefreshFrequencyMins           : 15
RefreshMode                    : PUSH
PSComputerName                 :

Du kan se att det DebugMode är None.

Om du vill konfigurera demonstrationen DebugMode använder du följande PowerShell-resurs:

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
}

Skapa nu en konfiguration med namnet TestProviderDebugMode:

Configuration ConfigTestDebugMode
{
    Import-DscResource -Name TestProviderDebugMode
    Node localhost
    {
        TestProviderDebugMode test
        {
            onlyProperty = "blah"
        }
    }
}
ConfigTestDebugMode

Innehållet i filen $env:SystemDrive\OutputFromTestProviderDebugMode.txt är 1.

Uppdatera nu providerkoden med följande skript:

$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

Det här skriptet genererar ett slumptal och uppdaterar providerkoden. Med DebugMode värdet false ändras aldrig innehållet i filen $env:SystemDrive\OutputFromTestProviderDebugMode.txt .

DebugMode Ange nu till ForceModuleImport i konfigurationsskriptet:

LocalConfigurationManager
{
    DebugMode = "ForceModuleImport"
}

När du kör skriptet igen bör du tänka på att innehållet i filen är annorlunda varje gång. Du kan köra Get-DscConfiguration för att kontrollera det. Kodfragmentet nedan visar resultatet av ytterligare två körningar. Dina resultat kan skilja sig åt när du kör skriptet.

PS C:\> Get-DscConfiguration -CimSession (New-CimSession localhost)

onlyProperty                            PSComputerName
------------                            --------------
20                                      localhost

PS C:\> Get-DscConfiguration -CimSession (New-CimSession localhost)

onlyProperty                            PSComputerName
------------                            --------------
14                                      localhost

DSC returnerar "oväntad svarskod InternalServerError" vid registrering med Windows Pull Server

När du tillämpar en metakonfiguration på en server för att registrera den med en instans av Windows Pull Server kan du få följande fel.

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>

Detta kan inträffa när certifikatet som används på servern för att kryptera trafik har ett eget namn (CN) som skiljer sig från det DNS-namn som används av noden för att matcha URL:en. Uppdatera Windows Pull Server-instansen för att använda ett certifikat med ett korrigerat namn.

Fel vid körning av Sysprep efter att en DSC-konfiguration har tillämpats

När du försöker köra Sysprep för att generalisera en Windows Server när du har tillämpat en DSC-konfiguration kan du få följande fel.

SYSPRP LaunchDll:Failure occurred while executing 'DscCore.dll,SysPrep_Cleanup', returned error code 0x2

Att generalisera en server när den har konfigurerats med Windows PowerShell Desired State Configuration är inte ett scenario som stöds. Tillämpa i stället konfigurationer på Windows när fasen Specialitet för Windows-installationen har slutförts.

Se även

Begrepp

Andra resurser