What is Desired State Configuration (DSC)?

With PowerShell 4.0, Microsoft has introduced a cool new Windows management platform, called Desired State Configuration, or DSC. Through this feature you can easily define and maintain your entire compute environment, including your Hyper-V hosts, in an automated way. The types of functions you can perform with DSC include but are not limited to managing roles and services, registry settings, users and groups and software updates and patches. You can even use DSC to manage your custom resources. So think of DSC as a means to enforce settings, policies and consistent states within your environment.
If you are configuring and deploying multiple Hyper-V hosts, DSC is an excellent way to facilitate consistency across those servers while simplifying and automating the setup and rollout. It’s also an excellent way to police your hosts in the case where someone else may have enabled non-Hyper-V related roles and features on them.
The built-in DSC resources which come with PowerShell include:

  • DSC Archive Restore
  • DSC Environment Resource
  • DSC File Resource
  • DSC Group Resource
  • DSC Log Resource
  • DSC Package Resource
  • DSC WindowsProcess Resource
  • DSC Registry Resource
  • DSC WindowsFeature Resource
  • DSC Script Resource
  • DSC Service Resource
  • DSC User Resource

To setup a DSC script resource, open a PowerShell_ISE(Interactive Scripting Environment) session as administrator and turn on the show script pane to create and edit a shell script. Let’s take an example of defining an environment variable you would like to create on all your Hyper-V hosts. The syntax of creating the resource is:

Environment [string] #ResourceName
{
Name = [string]
[ Ensure = [string] { Absent | Present } ]
[ Path = [bool] ]
[ DependsOn = [string[]] ]
[ Value = [string] ]
}

The example below defines an environment variable called HVServerPathEnvironmentVariable which will be created on each host if it doesn’t already exist (via the Ensure = “Present” property). Because the Path property is set to $true, the directory c:Tests will be appended to the PATH environment variable on each host.

Microsoft’s TechNet give a great series of overviews and “getting started” guides for using DSC to define your environment here. We’ll discuss more about DSC in later posts.

MARKET-LEADING BACKUP AND RECOVERY SOLUTIONS

Discover how Unitrends can help protect your organization's sensitive data