Desired State Configuration
Organizing files
TODO Add information from:
Common Problems
Notice that the version of the local modules (DscResources) should match the version of the remote. Otherwise, you may see an error such as:
The powershell dsc resource cChocoInstaller from module cChoco <BLAH VERSION> does not exist at the powershell module path nor is it registered as a wmi dsc resource.
Managing Disks
[See also notes in "Files, Paths, and Disks ---> Managing Disks"; again the notes are from Essential PowerShell Cmdlets for Auditing and Maintaining Storage.]
You can use the xStorage
module to manage storage using DSC. A sample script follows:
Configuration DataDisks
{
Import-DscResource -ModuleName xStorage
Node Localhost
{
xWaitForDisk Disk2
{
DiskNumber = 2
RetryIntervalSec = 60
RetryCount = 60
}
xDisk GVolume
{
DiskNumber = 2
DriveLetter = 'G'
FSLabel = 'UserData'
}
}
}
DataDisks -outputpath c:DataDisks
Start-DscConfiguration -Path c:dataDisks -wait -force -Verbose
To install the module and make sure that it does exist use:
Install-Module xStorage
Get-DSCResource
Managing Software
Visual Studio Code
It is possible to configure VS Code using DSC and the vscode
module. See instructions here.
TODO : Outline steps here. Unlike article, it should be better to install the program with Chocolatey, using the cChoco module.
Troubleshooting
TODO: Summarize steps from https://msdn.microsoft.com/en-us/powershell/dsc/troubleshooting
The xDscDiagnostics
module is very helpful for debugging DSC.
You may also need to enable the Analytic and Debug logs:
Update-xDscEventLogStatus -Channel Analytic -Status Enabled
Update-xDscEventLogStatus -Channel Debug -Status Enabled
On the machine that is the target of the configuration, use the command: Get-DscLocalConfigurationManager
to get the state of the configuration manager. Use Get-xDscOperation
to get an idea of whether progress is being made.
Resetting DSC
If with the command Get-DscLocalConfigurationManager
you get the message:
LCM is performing a consistency check.
for a long time, it is possible that the manager is stuck somehow.
The configuration state is stored in %windir%\system32\Configuration
. To see what is there:
Get-ChildItem -Path 'C:\Windows\System32\Configuration' -File -Force
To remove the current state:
Remove-DscConfigurationDocument -Stage Current, Pending, Previous -Verbose
Remove-DscConfigurationDocument -Stage Current, Pending, Previous -Verbose -Force
However, before removing stop the service:
$dscProcessID = Get-WmiObject msft_providers |
Where-Object {$_.provider -like 'dsccore'} |
Select-Object -ExpandProperty HostProcessIdentifier
Get-Process -Id $dscProcessID | Stop-Process -Force