PowerShell and Desire State Configuration (DSC) – The Basics

By | 2014-11-25T10:13:24+00:00 November 25th, 2014|Application Lifecycle Management (ALM)|0 Comments

With all the latest Microsoft releases it’s apparent that PowerShell and Desired State Configuration (DSC) is at the core of build, releases, and configuration management. If you have not learned PowerShell, now is the time to get on board. DSC is a recent practice that was released in early 2013.  The DSC uses PowerShell’s core features as its foundational building blocks.

Since PowerShell is at the foundation of DSC, we first need to start with the basics of PowerShell.  Those of you that already know PowerShell, this blog post might be a good overview.

What I will be covering in this post:

Some basic scripts and objects that are helpful to know when you are getting started.

Want I will not be covered in this post:

I will not be covering the DSC. I will be covering DSC in later posts, in what I am calling the Powerbits series.

PowerShell it is a very large topic and cannot be covered in one single post. There are a number of great PowerShell resources available.  I have listed a few of my favorite resource links that might be helpful.

The Basics:

One of the first objects that is different from the good old batch scripts is the PowerShell Pipeline.  Here is an example:

Exploring Objects:

Get-Item C:\scripts | Get-Members

Get-items retrieves the info from C:\Scripts and passes (using the | ) the output which is an object to the Get-Member.

The Get-Members tells us that the type of object we are examining is System.IO.DirectoryInfo.  Which is a .Net Class. This can be seen in the Member Type column in the output.


Next is the PowerShell Variables.  As you can image, they are like any other variable with some small differences.


  • Variables can be strongly typed by using [String]$MyVariable or [Int] $MyNumberedVariable
  • When a variable contains a space, it has to be enclosed in curly braces ${Version Number}.  Best practices is to avoid using variables with spaces.
  • New-Variable cmdlet can be used to create new variables.  The –Name parameter of this cmdlet becomes the variable name of the argument you specify for the –Value parameters get assigned to the variable.
    • New-Variable –Name ShellVersion –Value 4.0
      • Note the Value does not prefix the $


  • Automatic Variables are created by PowerShell to store the state of PowerShell. For example the $PWD is an automatic variable that represents the current directory


Other automatic variables are: $PID and $PHome.  $PSVersionTable examines the Windows PowerShell.

Windows PowerShell

  • $VerbosePreference variable is used to define the behavior in PowerShell. By Default, the SilentlyContinue message logging is set.  Which means that the cmdlet won’t produce a verbose logging, unless the –Verbose switch parameter is explicitly specified.  With the $VerbosePreference set to Continue, the cmdlet with verbose logging produces the verbose message automatically.


  • Environment variables store information related to the operating system environment.  The $Env:Path gives the value of path environment. $Env:Computername hostname

As you can see, PowerShell is a large topic with vast capabilities. As you become more comfortable with PowerShell, I know you will soon discover that is a critical tool for the toolbox.

Next week I will be covering the additional install for Azure and DSC.  So check out next week’s Powerbit, when a byte is too much and bit is all you need.

About the Author:

Leave A Comment