What change in Powershell 5 changes meaning of block curly brackets : <p>We recently updated the Powershell version on our build servers from 4.0 to 5.0. This change caused one of our build scripts to start failing in an unexpected way. </p>

<p>The code is used to determine which user guides should be included in our product. The code processes a list of xml nodes that describe all available documents with version and culture. We group by document title and culture and then select the most fitting version.</p>

<pre><code>$documents = Get-ListItemsFromSharePoint
$documents = $documents |
    Where-Object { $productVersion.CompareTo([version]$_.ows_Product_x0020_Version) -ge 0 } |
    Where-Object { -not ($_.ows_EncodedAbsUrl.Contains('/Legacy/')) }

Write-Verbose -Message "Filtered to: $($documents.length) rows"

# Filter to the highest version for each unique title per language
$documents = $documents | Group-Object { $_.ows_Title, $_.ows_Localisation } |
    ForEach-Object {
        $_.Group | Sort-Object { [version]$_.ows_Product_x0020_Version } -Descending | Select-Object -First 1
    }
</code></pre>

<p>In Powershell 4 this code correctly sorts the documents by title and culture and then selects the most suitable version. In Powershell 5 this code groups all documents in a single list and then selected the most suitable version from that list. Given that we have documents in multiple languages this means that only the language with the most suitable version will be present.</p>

<p>The issue was fixed by changing </p>

<pre><code>$documents = $documents | Group-Object { $_.ows_Title, $_.ows_Localisation } |
</code></pre>

<p>to</p>

<pre><code>$documents = $documents | Group-Object ows_Title, ows_Localisation |
</code></pre>

<p>Now I understand that the first syntax is not technically correct according to the documentation because Group-Object expects an array of property names to group on, however in Powershell 4 the code did return the desired results.</p>

<p>The question now is what changed in Powershell 5 that the original code worked in Powershell 4 but failed in Powershell 5.</p>
