是否可以从当前系统版本创建 PowerShell DSC 配置文件?

Bre*_*ski 9 powershell-v4.0 dsc

有没有办法从当前系统构建 PowerShell 所需状态配置 (DSC) 配置文件?反对从头开始构建整个文件?

Ste*_*ski 6

不直接。您必须独立处理要模块化的每个资源。

例如,如果您想对现有的 Windows 角色和功能进行建模,您可以编写类似的脚本

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

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

    $t += @'

}
'@
} {$t}
Run Code Online (Sandbox Code Playgroud)

每个资源在您希望如何识别您想要控制的事物方面都是独一无二的。