DSC Troubleshooting

If you want to troubleshoot DSC (Desired State Configuration)… You can easily run a DSC config script locally on your computer, apply the MOF manually on-demand and watch it apply in realtime as per the below.

2018-06-28_2159

The below are the lines of PowerShell code you need for testing. First though, make sure you run the entire DSC Configuration block of code – so it’s in memory, similar to how a function behaves. In the example below, my DSC configuration file is called ‘Main‘.


################################################################################
################## Compile the DSC Configuration & Generate the MOF file
################################################################################
$ComputerName = $env:COMPUTERNAME
Main nodeName $env:COMPUTERNAME OutputPath "$env:USERPROFILE\Desktop"
################################################################################
################## Apply the MOF file to the local computer
################################################################################
# DSC – Watch as it applies the MOF
Start-DscConfiguration Path "$env:USERPROFILE\Desktop" ComputerName $ComputerName Wait Verbose Force
# LCM – Apply
<#
LCM stands for: (Local Configuration Manager) this congured the local machine for DSC,
You could probably skip the LCM part in testing
#>
Set-DscLocalConfigurationManager Path "$env:USERPROFILE\Desktop" ComputerName $ComputerName Verbose Force
# LCM – Check
Get-DscLocalConfigurationManager
################################################################################
################## Troubleshooting DSC Application
################################################################################
Get-Job | fl *
# Last DSC events, newest to oldest
Get-WinEvent LogName "Microsoft-Windows-Dsc/Operational" | select first 20 | fl Message, time*
################################################################################
################## Troubleshooting DSC Modules
################################################################################
Find-Module Filter 'xRemoteFile' | fl *
Install-Module Name 'xRemoteFile'
Get-DscResource Name 'Registry' syntax

If you want a full demo of DSC, check out my other blog.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s