Getting Started with Powershell DSC

Published on 06 May 2018

DSC, or "Desired State Configuration" is a way of managing servers. Unlike something like GPO, you are not specifically telling Windows which individual settings to set, you are telling the server what you want to happen. As an example, you could run a configuration to install a Windows Feature:

    WindowsFeature RemoteServerAdministrationTools {
        Ensure = "Present"
        Name = "RSAT"
    }

Every time the configuration runs, it will ensure that the Remote Server Admin tools are run. On what? On the server (node) we tell it run on, which we do like this:

Node("Server1") {

    WindowsFeature RemoteServerAdministrationTools {
        Ensure = "Present"
        Name = "RSAT"
    }

But we need to make theis part of a configuration. A configuration (I called mine, MyConfig) is a set of configuration items:

Configuration MyConfig
{
    Node("Server1") {

        WindowsFeature RemoteServerAdministrationTools {
            Ensure = "Present"
            Name = "RSAT"
        }
    }
}

You can multiple configurations per server (node), and multiple nodes per configuration.

Once you have written your configuration, run it (like a normal Powershell script). You can it directly from Powershell, the ISE (or VSCODE), or save it as a .PS1 file and execute it.

When you run it, it will load into memory. You can then execute it. If you config is called "myconfig", simple enter "myconfig" and press Enter (or Return). When you run it, it will create a folder (also called "MyConfig" if that is what your configuration is called). At that point you are ready. Simply run the following to run your config:

Start-DscConfiguration myconfig -wait -Verbose


![DSC1](https://s3.eu-west-2.amazonaws.com/heywoodonline.com/pictures/DSC1.PNG)

And now you know the basics! Build up your scripts, and you can not only replace GPO, but get more and more of your configuration done automatically. Why logon to configure a server, when you can do it in an automated and repeatable manner?

comments powered by Disqus