9

Is there a way to build a PowerShell desired state configuration (DSC) configuration file from a current system? Opposed of building the entire file from scratch?

Brettski
  • 942
  • 3
  • 20
  • 30

4 Answers4

6

Not directly. You'd have to approach each resource you want to module independently.

For example, if you want to model the existing windows roles and features, you could script out something like

Get-WindowsFeature -ComputerName ny-web01 | 
? installed |
% {$t = ''} { $t += @"

WindowsFeature "Role-$($_.Name)"
{
    Name = '$($_.Name)'
    Ensure = 'Present'
"@ 
    if ($_.dependson)
    {
        $t += @"
    DependsOn = '[WindowsFeature]Role-$($_.Name)'
"@
    }

    $t += @'

}
'@
} {$t}

Each resource will be unique in how you want to identify those things you want to control.

Steven Murawski
  • 1,570
  • 3
  • 14
  • 25
  • Not pretty, but it does work. Though -ComputerName wasn't a valid option when I tried it. I guess it is still best to start from scratch. Thanks Steven! – Brettski Apr 15 '14 at 21:08
  • -computername isn't present on Win7/Server2008R2 but is available on newer oses. – Steven Murawski Sep 12 '14 at 16:24
1

If you have a web-server, you can use Desired State Generator to create configurations for your web sites, application pools and IIS components.

Not everything, but it could give you a head start.

Peter Hahndorf
  • 13,763
  • 3
  • 37
  • 58
1

There is now something called ReverseDSC which allows you to create DSC configuration files based on an existing system. It still doesn't work for all aspects of the system but supports many common scenarios.

Peter Hahndorf
  • 13,763
  • 3
  • 37
  • 58
0

I created a PowerShell module called DscBaseline as I didn't want to create these configurations from scratch. It builds DSC configurations based on the system it is launched from. Available at:

https://github.com/phbits/DscBaseline

https://www.powershellgallery.com/packages/DscBaseline/1.0

More information available in the README.md with the following excerpt showing the coverage.

Coverage

DscBaseline produces configurations for the following.

  1. Security Policy - Account Policy (SecurityPolicyDsc)
  2. Security Policy - Security Option (SecurityPolicyDsc)
  3. Security Policy - User Rights Assignment (SecurityPolicyDsc)
  4. Audit Policy (AuditPolicyDsc)
  5. Network (NetworkingDsc)
  6. Services (PSDscResources)
  7. *Group Policy - EXPERIMENTAL. See known issues for details. (PSDscResources)
phbits
  • 206
  • 1
  • 8