microsoft / DSCParser

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

ConvertTo-DSCObject doesn't deliver proper object when Import-DscResource module doesn't exists #18

Closed PrzemyslawKlys closed 2 years ago

PrzemyslawKlys commented 2 years ago

If you try to process DSC file while the Import-DSCResource references module that doesn't exists (in my case I had newer version) it would not deliver proper object

image

Object returned:

image


$Test = ConvertTo-DSCObject -Path C:\Support\GitHub\Testimo\Ignore\m365\M365TenantConfig.ps1 -IncludeComments $true
$Test | Format-Table
PrzemyslawKlys commented 2 years ago

The reason for this is the AST is different. Would require updating logic if at all possible, because there's a lot of differences

image

Probably better to detect this situation and write warning.

andikrueger commented 2 years ago

Within Microsoft365DSC there is logic to remove the required version entirely. This impacts the process if there are several versions of a module present. https://github.com/microsoft/Microsoft365DSC/blob/Dev/Modules/Microsoft365DSC/Modules/M365DSCReport.psm1#L33-L43

I really like the idea to show an information/warning about a miss match of versions.

PrzemyslawKlys commented 2 years ago

I think removing is one thing, but there should be logic to maybe not setting it up first.

andikrueger commented 2 years ago

I totally agree with you. Removing this part is just going around the problem - and this also cause some additional issues: see https://github.com/microsoft/Microsoft365DSC/issues/1725#issuecomment-1047227465