首页 > 解决方案 > In a powershell DSC resource declaration, what syntactical element is the declaration?

问题描述

I'm trying to figure out what syntactical element is in use for a Powershell DSC resource declaration. For example:

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

What exactly is the syntactical block between (and including) the two braces? It's not a hashtable (no @) nor is it a scriptblock (cos that would make the properties be Powershell statements). It feels like a parameter to the resource, so I'd like to understand the syntax.

标签: powershelldsc

解决方案


I can't find any definitive reference, but I think the entire SqlServerNetwork "RDBMS" { … } is a Dynamic Keyword Statement, and the { … } are "properties".

If you look at the source code for the PowerShell parser here:

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

there's this comment:

///     keyword [parameters] [name] { a=1; b=2; } # constructor with properties

in the xml comments for the DynamicKeywordStatementRule function, which matches the syntax of the DSC block.

If that's the case, the reference for DynamicKeywordStatementAst is here:

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

That's as far as I can get though. Hopefully someone else can give some more details.


推荐阅读