Select Page

Powershell 4.0 – Desired State Configuration

Powershell 4.0 – Desired State Configuration

If you’re like most Systems Admins you look for ways you can automate processes and build a more proactive and self-healing environment.  There are many applications out there which can be used to automate and orchestrate your environment. Some of the most common are:  Puppet, Chef, Ansible and Salt.  While all of these are very robust applications, there are some downsides if you are a windows heavy shop.  All of them have a pretty steep learning curve and require some sort of in-depth training to really comprehend and utilize them.  Secondly, although they all may integrate with windows, sometimes it’s not as easy and out of the box as we really would like.  Let’s be honest, not many of us have the time to fully test and train on a new product while still trying to keep our company up and running.

Powershell 4.0 brings a new set of cmdlets and keywords to help you automate processes and tasks in your windows environments.  If you know powershell, you’ve done the heavy lifting already so there’s no major learning curve.  It will also make the financial guys happy when you aren’t begging for piles of money to implement a new product and then get training before you can fully utilize it.  I’ve tried several of the big named IT automation applications, and although I found that some of them could be really amazing, I was left having to do all kinds of extra work and training to really get the most out of them at a Windows heavy company.

OK, so some may ask what really does desired state configuration mean? In simple terms:  we set a “state” in which we define how we may want a service, registry key or application to be.  We then use that state to constantly check or environment to make sure the machines are in the state we want them to be in.  In short it’s 3 steps:  1) set state  2)check state  3)fix state if needed.  Granted this is a very abbreviated synopsis of the process, but at the root it’s really not much more complicated.

So why would be use Powershell DSC? To automate and configure server/workstation states with minimal effort. Here are some examples of the types of things we can do:

  • Manage registry settings
  • Manage Processes and Services
  • Deploy Software
  • Manage User Accounts and Groups
  • Run Scripts
  • Manage Server Roles and Features
  • Manage Files and Folders
  • Fix machines that are no longer in our desired state
  • Check configuration and states of machines

Powershell DSC can be a very powerful tool and allow you to become a more proactive systems administrator.  So let me give you a really quick example to allow you to see the process. In this example we will ensure the DNS Server windows feature is installed.  If you need a full list of windows features, you can run the Get-WindowsFeature command from powershell.

Configuration DNSServer { param ($MachineName) Node $MachineName { #Install the DNSRole WindowsFeature IIS { Ensure = “Present” Name = “DNS Server” } } }Content goes here
DNSServer -MachineName “MyTestServer”
Start-DscConfiguration -Path .\DNSServer -Wait -Verbose
Test-DscConfiguration -CimSession $session

That’s it!  Short, sweet and simple.  This example is very basic but it should give you an understanding of how easy it is to use Powershell DSC. Be on the lookout for more posts on DSC and the best way to learn is go out there and play around with it.

 

About The Author

Dan Kelly

Graduating from college in 2002 with a bachelors in Computer Science, I quickly became aware that my degree didn’t really prepare me for a real-world career. Not having the time and/or patience to take more college courses I set upon trying to teach myself the real world tools I would need to be successful. I quickly realized that I learn extremely well when I can take something I read/hear and then take it to the real world and do it. Nowadays, you can’t be successful if you don’t have a working knowledge of many process, applications, platforms etc and build your IT Toolbox to be able to fix pretty much anything. Most of the time you can find information you need in books and classes, but those don’t give you the real-world solutions and information that you need right now pertaining to your problem. I have gathered a lot of tips, secrets and knowledge of a multitude of IT related areas, but I can always gain more and wanted a place to share the things I’ve learned along the way. ITDiversified gives that platform for knowledge sharing and hopefully it can become a sort of cross-training ground for many IT professionals who need a nice central repository of knowledge on demand.

2 Comments

    • DK

      Excellent, thanks for the info Jeffrey! I plan on testing and implementing DSC even more and providing more in depth posts on everything. The DSC ability of powershell is something kinda flying under the radar right now from everyone I’ve talked to and we really want to try and bring it out to public knowledge.

      Reply

Leave a reply

Your email address will not be published.