The Startup
Published in

The Startup

Image by Michal Jarmoluk from Pixabay

Automate Services DSC Configuration Via PowerShell

Microsoft Desired State Configuration (DSC) is a management platform where configurations use a declarative syntax. Traditionally configurations are made by finding the particular Group Policy setting (local or otherwise). With DSC, all of the settings are in a text file stating the desired value (i.e. declared) making configuration as code possible.

One of the difficulties adopting DSC is generating the configuration files as it can be quite time-consuming. Suppose you have a server in its production configuration that needs to be migrated to DSC. Generating the configuration for Services alone will take significant time let alone the Security Policy and one-off registry settings. I found myself spending far too much time on this and thus wrote this PowerShell function to automate the process.

EDIT: 2021–03–18

This script was an initial attempt to automate the creation of a DSC configuration. It has since been improved and incorporated into DscBaseline. A tutorial for using DscBaseline is available here on Medium at: Creating DSC Configurations with DscBaseline

The following function is hosted on GitHub Gist and can be launched via either of the following methods:

  • Option #1 — Copy/Paste the function into an existing PowerShell window. Then run the command Get-ServiceDscConfig. A configuration file will be created in the current working directory.
  • Option #2 — Copy/Paste the function into a file called GetServiceDscConfig.ps1 (or whatever name you prefer). Remove the function declaration (e.g. Function Get-ServiceDscConfig) and the first open curly bracket (e.g. {). Next, delete the last closing curly bracket (e.g. }) which should be the last line. Now run the script as GetServiceDscConfig.ps1 to produce the configuration.

 by the author.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store