microsoft / DSCParser

Allows the conversion of DSC scripts into PSObject for analysis purposes
MIT License
29 stars 21 forks source link

ConvertTo-DSCObject does not work in Powershell 7.1.1 #15

Closed 1ict closed 3 years ago

1ict commented 3 years ago

ConvertTo-DSCObject hangs on endless loop on Powershell 7.1.1

ConvertTo-DSCObject, from line 81 :

      elseif ($parsedData[$i].Content -eq 'node')
        {
            $nodeKeyWordEncountered = $true
            $newIndexPosition = $i+1
            while ($parsedData[$newIndexPosition].Type -ne 'Keyword')
            {
                $i++
                $newIndexPosition = $i+1
            }
        }

Loops endlessly because there's no more 'Keyword' tokens

The PSParser in Powershell 7.1.1 gives different tokentypes for some tokens. (not sure if this is a bug or intentionally, https://github.com/PowerShell/PowerShell/pull/13779 is the only change i found involving the parser in recent releases)

the DSC Resource on this page : http://nikcharlebois.com/cloud-lcm-prototype-for-dsc-as-a-service/ gives these token types (just listed the ones that are different in pre-7.1.1 and 7.1.1)

Content Type (< 7.1.1) Type (7.1.1) Start
AADMSGroupLifecyclePolicy Keyword Command 809
aa1d0235-e1aa-4c52-a496-f96c81f7d2f4 Command CommandArgument 835
IsSingleInstance Member Command 896
= Operator CommandArgument 924
GroupLifetimeInDays Member Command 946
= Operator CommandArgument 974
ManagedGroupTypes Member Command 993
= Operator CommandArgument 1021
AlternateNotificationEmails Member Command 1042
= Operator CommandArgument 1070
Ensure Member Command 1116
= Operator CommandArgument 1144
GlobalAdminAccount Member Command 1170
= Operator CommandArgument 1198
AADGroupsNamingPolicy Keyword Command 1239
CustomBlockedWordsList Member Command 1304
= Operator CommandArgument 1334
GlobalAdminAccount Member Command 1372
= Operator CommandArgument 1402
IsSingleInstance Member Command 1436
= Operator CommandArgument 1466
PrefixSuffixNamingRequirement Member Command 1488
= Operator CommandArgument 1518

Again not sure if it should be fixed here... But it should atleast throw an error if $i becomes larger than $parsedData.Count to prevent an endless loop

1ict commented 3 years ago

seems to be something weird with my psparser! downgraded to pwsh 7.0.3 but keep getting the same result . on other machines i get correct results need more investigation on my part.

turned out microsoft365dsc didnt load completely in pwsh7, really thought it was :) my bad