Can a PowerShell DSC configuration file be created from a current system build

dscpowershell-v4.0

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?

Best Answer

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.

Related Topic