3

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.

Peter McEvoy
  • 2,816
  • 19
  • 24

1 Answers1

3

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://learn.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.

mclayton
  • 8,025
  • 2
  • 21
  • 26
  • Wow - that's a great find. I knew DSC added new syntax elements and I guess this is it.. (Now I'll walk away slowly from this mine field!) – Peter McEvoy Oct 31 '18 at 10:03