Saturday, 1 July 2017

DSC for beginners Part 1

Why DSC?
This could make your life a lot easier and finally this is a Configuration Management piece which is powerful.

There are a lot of books and videos that could help you to gain a lot of in-depth knowledge on this  when it comes to DSC learning.
The same problem, fear the shell and this one goes above quickly if you not ready and this one comes with another layer of do this {...} list before you start even experimenting.

This post doesn't deal with any theory, which you still have to get it from the books or the online content. This would get you started right away which i personally believe is bad but until you experiment you don't know its potential.

Note: Use a disposable Virtual Machine these tools are powerful and could make a system unusable quickly, finally I ended up warning you with my post.

Take Windows Server 2012 R2 and patch it with KB2883200 , (Link opens up in new window and the file is around 224MB) then we are ready.

Few very highly simplified definitions to know.

What is LCM (Local Configuration Manager) :
  • LCM is the engine for DSC which runs on all nodes, this is the one which does the configuration part. This has to be set initially so that the server stays how you want it using the DSC scripts used later.
  • LCM Setting : ApplyAndAutoCorrect :The default LCM Configuration is 'ApplyAndMonitor' we need to change this to 'ApplyAndAutoCorrect'. So that it would correct the drift.

Run the below command to verify the status.
Get-DscLocalConfigurationManager



Open Powershell ISE as Administrator and run this code to change the 'ApplyAndMonitor' to 'ApplyAndAutoCorrect' so that the drift (how you want the system to be to how something changed.) would be auto-corrected by LCM.

[DscLocalConfigurationManager()]
Configuration SetTheLCM
{

    Settings
    {
        ConfigurationMode = "ApplyAndAutoCorrect"
        RefreshMode = "Push"
        RefreshFrequencyMins = 30
    }


}
SetTheLCM



This would create a folder under the current directory with the same name "SetTheLCM" where it saves the .mof file that should be called to change the LCM with our desired change.

Run the below command to make the change, try to use -Verbose as much as you can.

Set-DscLocalConfigurationManager -Path .\SetTheLCM -Verbose
Once the output returns without any errors.

Verify the status of LCM, if the desired change is in effect ''ApplyAndAutoCorrect"

 Get-DscLocalConfigurationManager
Output should look like below.



Now, we are ready to start our first example on how DSC would handle Configuration Management.

DSC Example 1 - > Click Here : DSC Example.

Good Source for DSC Learning : 
  1. https://channel9.msdn.com/Series/Getting-Started-with-PowerShell-Desired-State-Configuration-DSC

Happy Scripting.


1 comment: