Home Dashboard Directory Help

Unexpected Token '}' in Expression or Statement when using $AllNodes in a Desired State Configuration by azhskr


 as By Design Help for as By Design

Sign in
to vote
Type: Bug
ID: 1491585
Opened: 6/30/2015 12:37:30 PM
Access Restriction: Public
User(s) can reproduce this bug


When I try to build a Configuration like the one below, it fails with the error "Error" Unexpected Token '}' in expression or statement.
Configuration TestConfig{
    Import-DscResource -ModuleName @{ModuleName="xComputerManagement";ModuleVersion="1.3.0"
    Node $AllNodes.Nodename{
        xComputer Test{
            Name = "MYPC"
However, if I put a space between $AllNodes.NodeName and the curly brace, everything works fine. This is obviously a problem. I don't need a space between the name of the Configuration and the curly brace, and if I replace $AllNodes.NodeName with something like localhost, it works just fine without a space between localhost and the curly brace as well.
Sign in to post a comment.
Posted by Microsoft on 12/8/2015 at 10:14 AM
Hi azhskr,

This is a direct result of the language feature that Derp described and cannot be mitigated without breaking changes that reduce functionality in the language.

However, we did add an error message in the most recent version of PowerShell 5.0 that instructs the user to add a space rather than give the more generic error message you were seeing before. Hope that helps!

Posted by azhskr on 7/1/2015 at 6:41 AM
That's great and all, but nowhere else in PowerShell is there a space required after a string and a curly brace, and this shouldn't require one either. For purposes of consistency and ease of use, this is an issue that needs to be fixed.
Posted by Derp McDerp on 6/30/2015 at 5:36 PM
(From my vague memory so I might be wrong:) when PowerShell team added the .Where and .ForEach methods to all collection types, e.g.:

(1..10).ForEach({$_ * 20})

It also allowed:


as syntax sugar for:


This is why the code above requires a space.
Sign in to post a workaround.