在Powershell DSC资源声明中,声明是什么语法元素?

时间:2018-10-30 16:06:09

标签: powershell dsc

我正在尝试弄清楚Powershell DSC资源声明中使用了什么语法元素。例如:

    SqlServerNetwork "RDBMS"
    {
        DependsOn = @("[SqlSetup]RDBMS")
        InstanceName = "MSSQLSERVER"
        ProtocolName = "tcp"
        IsEnabled = $true
        TCPPort = 1433
        RestartService = $true 
    }

两个括号之间的语法障碍到底是什么?它既不是哈希表(不是@),也不是脚本块(使属性成为Powershell语句的cos)。感觉就像是资源的参数,所以我想了解语法。

1 个答案:

答案 0 :(得分:3)

我找不到任何确定的引用,但我认为整个SqlServerNetwork "RDBMS" { … }是动态关键字声明,而{ … }是“属性”。

如果您在此处查看PowerShell解析器的源代码:

https://github.com/PowerShell/PowerShell/blob/720e842c86722e9fb51e191c39bd8307d79da11a/src/System.Management.Automation/engine/parser/Parser.cs#L3579

有此评论:

///     keyword [parameters] [name] { a=1; b=2; } # constructor with properties
DynamicKeywordStatementRule函数的xml注释中

与DSC块的语法匹配。

在这种情况下,DynamicKeywordStatementAst的引用在这里:

https://docs.microsoft.com/en-us/dotnet/api/system.management.automation.language.dynamickeywordstatementast?view=pscore-6.0.0

尽我所能。希望其他人可以提供更多详细信息。

相关问题