Pemecahan masalah DSC
Berlaku Untuk: Windows PowerShell 4.0, Windows PowerShell 5.1
Artikel ini menyediakan instruksi pemecahan masalah untuk kesalahan umum.
Dependensi WinRM
Windows PowerShell Desired State Configuration (DSC) bergantung pada WinRM. WinRM tidak diaktifkan secara default pada Windows Server 2008 R2 dan Windows 7. Jalankan Set-WSManQuickConfig
, dalam sesi Windows PowerShell ditingkatkan, untuk mengaktifkan WinRM.
Menggunakan Get-DscConfigurationStatus
Cmdlet Get-DscConfigurationStatus mendapatkan informasi tentang status konfigurasi dari simpul target. Perintah mengembalikan objek kaya yang menyertakan informasi tingkat tinggi tentang apakah eksekusi konfigurasi berhasil atau tidak. Anda dapat menggali objek untuk menemukan detail tentang konfigurasi yang dijalankan seperti:
- Setiap sumber daya yang gagal.
- Sumber daya apa pun yang meminta boot ulang.
- Meta-Configuration pengaturan pada saat konfigurasi berjalan.
Kumpulan parameter berikut mengembalikan informasi status untuk eksekusi konfigurasi terakhir:
Get-DscConfigurationStatus [-CimSession <CimSession[]>]
[-ThrottleLimit <int>]
[-AsJob]
[<CommonParameters>]
Kumpulan parameter berikut mengembalikan informasi status untuk setiap eksekusi konfigurasi:
Get-DscConfigurationStatus -All
[-CimSession <CimSession[]>]
[-ThrottleLimit <int>]
[-AsJob]
[<CommonParameters>]
Contoh
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 :
Skrip saya tidak akan berjalan: Menggunakan log DSC untuk mendiagnosis kesalahan skrip
Seperti semua perangkat lunak Windows, DSC merekam kesalahan dan peristiwa dalam log yang tersedia untuk ditinjau di Pemantau Peristiwa. Memeriksa log ini dapat membantu Anda memahami mengapa operasi tertentu gagal, dan cara mencegah kegagalan di masa depan. Untuk mempermudah kesalahan pelacakan saat Anda menulis, gunakan sumber daya Log DSC untuk melacak kemajuan konfigurasi Anda di log peristiwa DSC Analytic.
Di mana log peristiwa DSC?
Dalam Pemantau Peristiwa, peristiwa DSC ada di: Log Aplikasi dan Layanan/Microsoft/Windows/Konfigurasi Status yang Diinginkan
Anda dapat menjalankan cmdlet PowerShell yang sesuai, Get-WinEvent, untuk melihat log peristiwa:
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} :
Nama log utama DSC adalah Microsoft-Windows-DSC>> (nama log lain di bawah Windows tidak ditampilkan di sini untuk keringkasan). Nama utama ditambahkan ke nama saluran untuk membuat nama log lengkap.
Mesin DSC menulis terutama ke dalam tiga jenis log: log Operasional, Analitik, dan Debug. Karena log analitik dan debug tidak diaktifkan secara default, Anda harus mengaktifkannya di Pemantau Peristiwa. Untuk melakukan ini:
Buka Pemantau Peristiwa dengan:
- Mengetik
Show-EventLog
di Windows PowerShell - Memilih tombol Mulai, lalu Panel Kontrol, lalu Alat Administratif, lalu Pemantau Peristiwa.
- Mengetik
Pada menu Tampilan di Penampil peristiwa, pilih Tampilkan Log Analitik dan Debug.
Nama log untuk saluran analitik adalah
Microsoft-Windows-Dsc/Analytic
, dan saluran debug adalahMicrosoft-Windows-Dsc/Debug
.
Anda juga dapat menggunakan utilitas wevtutil untuk mengaktifkan log, seperti yang ditunjukkan dalam contoh berikut.
wevtutil.exe set-log "Microsoft-Windows-Dsc/Analytic" /q:true /e:true
Atau, gunakan PowerShell dan .NET untuk mengaktifkan log seperti yang diperlihatkan dalam contoh berikut:
$logName = 'Microsoft-Windows-Dsc/Analytic'
$log = New-Object System.Diagnostics.Eventing.Reader.EventLogConfiguration $logName
$log.IsEnabled = $true
$log.SaveChanges()
Apa yang dimuat log DSC?
DSC mencatat ke tiga saluran log yang berbeda berdasarkan pentingnya pesan. Log operasional di DSC mencakup semua pesan kesalahan, dan berguna untuk mengidentifikasi masalah. Log analitik memiliki volume peristiwa yang lebih tinggi, dan dapat mengidentifikasi di mana kesalahan terjadi. Saluran ini juga mencakup pesan verbose yang dipancarkan. Log debug memiliki log yang dapat membantu Anda memahami bagaimana kesalahan terjadi. Pesan peristiwa DSC dimulai dengan ID pekerjaan yang secara unik mewakili operasi DSC. Contoh berikut mencoba untuk mendapatkan pesan dari peristiwa pertama yang masuk ke log DSC operasional.
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 mencatat peristiwa dengan struktur yang memungkinkan pengguna mengumpulkan peristiwa dari satu pekerjaan DSC. Strukturnya adalah sebagai berikut:
Job ID : <Guid>
<Event Message>
Mengumpulkan peristiwa dari satu operasi DSC
Log peristiwa DSC berisi peristiwa yang dihasilkan oleh berbagai operasi DSC. Namun, biasanya Anda khawatir dengan detail untuk operasi tertentu. Semua log DSC dapat dikelompokkan menurut properti ID pekerjaan yang unik untuk setiap operasi DSC. ID pekerjaan menunjukkan sebagai nilai properti pertama di semua peristiwa DSC. Langkah-langkah berikut menjelaskan cara mengakumulasi semua peristiwa dalam struktur array yang dikelompokkan.
<##########################################################################
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}
Di sini, variabel $SeparateDscOperations
menyertakan log yang dikelompokkan menurut ID pekerjaan. Setiap elemen array dari variabel ini mewakili sekelompok peristiwa yang dicatat oleh operasi DSC yang berbeda, memungkinkan akses ke informasi lebih lanjut tentang log.
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} : ...
Anda dapat mengekstrak data dalam variabel $SeparateDscOperations
menggunakan Where-Object.
Berikut ini adalah lima skenario di mana Anda mungkin ingin mengekstrak data untuk pemecahan masalah DSC:
1: Kegagalan operasi
Semua peristiwa memiliki tingkat keparahan. Informasi ini berguna untuk mengidentifikasi peristiwa kesalahan:
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: Detail operasi yang dijalankan dalam setengah jam terakhir
TimeCreated
, properti dari setiap peristiwa Windows, menyatakan waktu peristiwa dibuat. Membandingkan properti ini dengan objek tanggal/waktu tertentu berguna untuk memfilter semua peristiwa:
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: Pesan dari operasi terbaru
Operasi terbaru disimpan dalam indeks pertama grup $SeparateDscOperations
array .
Mengkueri pesan grup untuk indeks 0 mengembalikan semua pesan untuk operasi terbaru:
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: Pesan kesalahan yang dicatat untuk operasi yang gagal baru-baru ini
$SeparateDscOperations[0].Group
memiliki serangkaian peristiwa untuk operasi terbaru. Jalankan Where-Object
cmdlet untuk memfilter peristiwa berdasarkan nama tampilan tingkatnya. Hasil disimpan dalam $myFailedEvent
variabel , yang dapat dibedakan lebih lanjut untuk mendapatkan pesan peristiwa:
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: Semua peristiwa yang dihasilkan untuk ID pekerjaan tertentu.
$SeparateDscOperations
adalah array grup, yang masing-masing memiliki nama sebagai ID pekerjaan unik. Dengan menjalankan Where-Object
cmdlet , Anda dapat mengekstrak grup peristiwa yang memiliki ID pekerjaan tertentu:
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} : ...
Menggunakan xDscDiagnostics untuk menganalisis log DSC
xDscDiagnostics adalah modul PowerShell yang terdiri dari beberapa fungsi yang dapat membantu menganalisis kegagalan DSC pada komputer Anda. Fungsi-fungsi ini dapat membantu Anda mengidentifikasi semua peristiwa lokal dari operasi DSC sebelumnya, atau peristiwa DSC di komputer jarak jauh. Di sini, istilah operasi DSC mendefinisikan satu eksekusi DSC unik dari awal hingga akhir. Misalnya, Test-DscConfiguration
akan menjadi operasi DSC terpisah. Demikian pula, setiap cmdlet lainnya di DSC, seperti Get-DscConfiguration
dan Start-DscConfiguration
, dapat diidentifikasi sebagai operasi DSC terpisah. Untuk informasi selengkapnya tentang fungsi diagnostik, lihat xDscDiagnostics.
Mendapatkan detail operasi DSC
Fungsi ini Get-xDscOperation
memungkinkan Anda menemukan hasil operasi DSC yang berjalan pada satu atau beberapa komputer. Fungsi mengembalikan objek yang memiliki kumpulan peristiwa yang dihasilkan oleh setiap operasi DSC. Misalnya, dalam output berikut, tiga perintah dijalankan. Yang pertama lolos, dan dua lainnya gagal. Output meringkas Get-xDscOperation
hasil ini.
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...
Anda bisa mendapatkan hasil hanya untuk operasi terbaru dengan menentukan parameter Terbaru :
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...
Mendapatkan detail peristiwa DSC
Trace-xDscOperation
Cmdlet mengembalikan objek yang berisi kumpulan peristiwa, jenis peristiwanya, dan output pesan yang dihasilkan dari operasi DSC tertentu. Biasanya, ketika Anda menemukan kegagalan di salah satu operasi menggunakan Get-xDscOperation
, Anda akan melacak operasi tersebut untuk menemukan peristiwa yang menyebabkan kegagalan.
SequenceID
Gunakan parameter untuk mendapatkan peristiwa untuk operasi tertentu untuk komputer tertentu.
Misalnya, jika Anda menentukan SequenceID
9, Trace-xDscOperation
dapatkan jejak untuk operasi DSC yang ke-9 dari operasi terakhir:
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.
Teruskan GUID yang ditetapkan ke operasi DSC tertentu (seperti yang dikembalikan oleh Get-xDscOperation
cmdlet) untuk mendapatkan detail peristiwa untuk operasi DSC tersebut:
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
Perhatikan bahwa, karena Trace-xDscOperation
menggabungkan peristiwa dari log Analitik, Debug, dan Operasional, log ini meminta Anda untuk mengaktifkan log ini.
Secara bergantian, Anda dapat mengumpulkan informasi tentang peristiwa dengan menyimpan output Trace-xDscOperation
ke dalam variabel. Anda dapat menggunakan perintah berikut untuk menampilkan semua peristiwa untuk operasi DSC tertentu.
PS C:\DiagnosticsTest> $Trace = Trace-xDscOperation -SequenceID 4
PS C:\DiagnosticsTest> $Trace.Event
Ini menampilkan hasil Get-WinEvent
yang sama dengan cmdlet, seperti dalam output berikut:
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.
Idealnya, Anda pertama-tama akan menggunakan Get-xDscOperation
untuk mencantumkan beberapa konfigurasi DSC terakhir yang berjalan di komputer Anda. Setelah ini, Anda dapat memeriksa operasi tunggal apa pun dengan menentukan SequenceID atau JobID-nyaTrace-xDscOperation
untuk menemukan apa yang dilakukannya di belakang layar.
Mendapatkan peristiwa untuk komputer jarak jauh
ComputerName
Gunakan parameter Trace-xDscOperation
cmdlet untuk mendapatkan detail peristiwa di komputer jarak jauh. Sebelum dapat melakukan ini, Anda harus membuat aturan firewall untuk memperbolehkan administrasi jarak jauh pada komputer jarak jauh:
New-NetFirewallRule -Name "Service RemoteAdmin" -DisplayName "Remote" -Action Allow
Sekarang Anda dapat menentukan komputer tersebut dalam panggilan Anda ke 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...
Sumber daya saya tidak akan diperbarui: Cara mengatur ulang cache
Mesin DSC menyimpan sumber daya cache yang diimplementasikan sebagai modul PowerShell untuk tujuan efisiensi. Namun, ini dapat menyebabkan masalah ketika Anda menulis sumber daya dan mengujinya secara bersamaan karena DSC memuat versi cache hingga proses dimulai ulang. Satu-satunya cara untuk membuat DSC memuat versi yang lebih baru adalah dengan secara eksplisit mematikan proses yang menghosting mesin DSC.
Demikian pula, ketika Anda menjalankan Start-DscConfiguration
, setelah menambahkan dan memodifikasi sumber daya kustom, modifikasi mungkin tidak dijalankan kecuali, atau sampai, komputer di-boot ulang. Ini karena DSC berjalan dalam Proses Host Penyedia WMI (WmiPrvSE
), dan biasanya, ada banyak instans WmiPrvSE yang berjalan sekaligus. Saat Anda me-reboot, proses host memulai ulang dan menghapus cache.
Agar berhasil mendaur ulang konfigurasi dan menghapus cache tanpa memulai ulang, Anda harus berhenti lalu memulai ulang proses host. Ini dapat berdasarkan per instans, di mana Anda mengidentifikasi proses, menghentikannya, dan memulai ulang. Atau, Anda dapat menggunakan DebugMode
, seperti yang ditunjukkan di bawah ini, untuk memuat ulang sumber daya PowerShell DSC.
Untuk mengidentifikasi proses yang menghosting mesin DSC, cantumkan ID WmiPrvSE
proses dari , yang menghosting mesin DSC. Kemudian, untuk memperbarui penyedia, hentikan WmiPrvSE
proses menggunakan perintah di bawah ini, lalu jalankan Start-DscConfiguration
lagi.
###
### 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
Menggunakan DebugMode
Anda dapat mengonfigurasi DSC Local Configuration Manager (LCM) untuk digunakan DebugMode
untuk selalu menghapus cache saat proses host dimulai ulang. Ketika diatur ke $true
, hal ini menyebabkan mesin selalu memuat ulang sumber daya PowerShell DSC. Setelah selesai menulis sumber daya, Anda dapat mengaturnya kembali dan $false
mesin kembali ke perilaku penembolokan modul.
Berikut ini adalah demonstrasi untuk menunjukkan bagaimana DebugMode
dapat secara otomatis me-refresh cache. Pertama, mari kita lihat konfigurasi default:
Get-DscLocalConfigurationManager
AllowModuleOverwrite : False
CertificateID :
ConfigurationID :
ConfigurationMode : ApplyAndMonitor
ConfigurationModeFrequencyMins : 30
Credential :
DebugMode : {None}
DownloadManagerCustomData :
DownloadManagerName :
LocalConfigurationManagerState : Ready
RebootNodeIfNeeded : False
RefreshFrequencyMins : 15
RefreshMode : PUSH
PSComputerName :
Anda dapat melihat bahwa DebugMode
adalah None
.
Untuk menyiapkan DebugMode
demonstrasi, gunakan sumber daya PowerShell berikut:
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
}
Sekarang, tulis konfigurasi yang disebut TestProviderDebugMode
:
Configuration ConfigTestDebugMode
{
Import-DscResource -Name TestProviderDebugMode
Node localhost
{
TestProviderDebugMode test
{
onlyProperty = "blah"
}
}
}
ConfigTestDebugMode
Konten file $env:SystemDrive\OutputFromTestProviderDebugMode.txt
adalah 1
.
Sekarang, perbarui kode penyedia menggunakan skrip berikut:
$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
Skrip ini menghasilkan angka acak dan memperbarui kode penyedia. Dengan DebugMode
diatur ke false, konten file $env:SystemDrive\OutputFromTestProviderDebugMode.txt
tidak pernah diubah.
Sekarang, atur DebugMode
ke ForceModuleImport
dalam skrip konfigurasi Anda:
LocalConfigurationManager
{
DebugMode = "ForceModuleImport"
}
Saat Anda menjalankan skrip lagi, perhatikan bahwa konten file berbeda setiap saat. Anda dapat menjalankan Get-DscConfiguration
untuk memeriksanya. Cuplikan di bawah ini menunjukkan hasil dua eksekusi lagi. Hasil Anda mungkin berbeda saat Anda menjalankan skrip.
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 mengembalikan "kode respons tak terduga InternalServerError" saat mendaftar dengan Windows Pull Server
Saat menerapkan metakonfigurasi ke server untuk mendaftarkannya dengan instans Windows Pull Server, Anda mungkin mendapatkan kesalahan berikut.
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>
Ini dapat terjadi ketika sertifikat yang digunakan pada server untuk mengenkripsi lalu lintas memiliki nama umum (CN) yang berbeda dari nama DNS yang digunakan oleh simpul untuk mengatasi URL. Perbarui instans Windows Pull Server untuk menggunakan sertifikat dengan nama yang dikoreksi.
Kesalahan saat menjalankan Sysprep setelah menerapkan Konfigurasi DSC
Saat mencoba menjalankan Sysprep untuk menggeneralisasi Windows Server setelah menerapkan konfigurasi DSC, Anda mungkin mendapatkan kesalahan berikut.
SYSPRP LaunchDll:Failure occurred while executing 'DscCore.dll,SysPrep_Cleanup', returned error code 0x2
Menggeneralisasi server setelah dikonfigurasi menggunakan Windows PowerShell Desired State Configuration bukanlah skenario yang didukung. Sebagai gantinya, terapkan konfigurasi ke Windows setelah fase Spesialisasi Penyetelan Windows selesai.
Lihat juga
Konsep
Sumber Daya Lain
Saran dan Komentar
https://aka.ms/ContentUserFeedback.
Segera hadir: Sepanjang tahun 2024 kami akan menghentikan penggunaan GitHub Issues sebagai mekanisme umpan balik untuk konten dan menggantinya dengan sistem umpan balik baru. Untuk mengetahui informasi selengkapnya, lihat:Kirim dan lihat umpan balik untuk