Saturday, 1 July 2017

DSC for beginners Part 2


If you are here on this page directly because of the search engine, you need to go here first -> DSC for beginners Part 1 and i mean it.

Managing nodes from a Configuration Management tool is healthy than logging into the servers.
This would simplify the change management and the risk of human errors.

We jump to the example :
The very common problem, a configuration (editable file) being changed causing issues in the environment. We want to keep the file as it is.

Once the LCM is set as per the earlier post,open ISE and paste the code below.

#I Have no app running on this VM.
#This is to provide demo.
#This would create the file with the desired contents if deleted.
#This would revert changes inside the file if altered.
Configuration ImportantFile

   File KeepTheFileandContent
       Ensure = 'Present'
       Type = 'File'
       DestinationPath = 'C:\MyAppConfig\App.conf'
       Contents = "appPath = C:\MyAppConfig"

ImportantFile -OutputPath C:\ImportantFile\

To initiate the configuration

Start-DscConfiguration -Path C:\ImportantFile\ -Verbose -Wait

Now you could do the

Test 1

Delete the file C:\MyAppConfig\App.conf

Test 2
Edit the content of the file C:\MyAppConfig\App.conf

Give it some time.

The server/node could be validated if its in the desired state by executing

Test-DscConfiguration -Verbose

Output: True indicates the server is in the desired state with the configuration defined.

PowerShell DSC is very rich in features, this initial post is just the scope what it could do.

Good Source for DSC Learning :

Happy Scripting.

No comments:

Post a Comment