microsoft / DSCParser

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

Error handling of custom DSC resources in config #42

Open ssoabx opened 7 months ago

ssoabx commented 7 months ago

Using 2.0.0.3 of the module via the recently published Microsoft365DSC release I'm getting lots of errors. One is related to our own DSC resource being present in the master config. The following error related to this is thrown (German sorry..):

Get-Module : Das Argument für den Parameter "Name" kann nicht überprüft werden. Das Argument ist NULL oder leer. Geben Sie ein Argument an, das nicht NULL oder leer ist, und führen Sie den Befehl    erneut aus. 
In C:\Program Files\WindowsPowerShell\Modules\DSCParser\2.0.0.3\Modules\DSCParser.psm1:341 Zeichen:46
+ ... $loadedModuleTest = Get-Module -Name $moduleToLoad.ModuleName -ListAv ...
+                                          ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidData: (:) [Get-Module], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetModuleCommand
Get-DscResource : Das Argument für den Parameter "Module" kann nicht überprüft werden. Das Argument ist NULL oder leer. Geben Sie ein Argument an, das nicht NULL oder leer ist, und führen Sie den    Befehl erneut aus.
In C:\Program Files\WindowsPowerShell\Modules\DSCParser\2.0.0.3\Modules\DSCParser.psm1:349 Zeichen:57
+ ...  $currentResources = Get-DSCResource -Module $moduleToLoad.ModuleName
+                                                  ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidData: (:) [Get-DscResource], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Get-DscResource

https://github.com/microsoft/DSCParser/blob/d6c7f365fb91e697890755db376b3fb2ef420ad0/Modules/DSCParser/Modules/DSCParser.psm1#L338-L357

Start of said MasterConfig.ps1:

Configuration MasterConfig
{
    param (
    )

    $OrganizationName = $ConfigurationData.NonNodeData.OrganizationName
    if ($ConfigurationData.NonNodeData.Shortname) {$short=$ConfigurationData.NonNodeData.Shortname}
    Else {$short="Org"}

    Import-DscResource -ModuleName 'Microsoft365DSC','Microsoft365DSCCustomRes'

    Node localhost
    {

        ......

On the old 1.4.0.4 version this didn't result in an error.

Removing it from the config removes the error (expected). Adding it as a separate line in the expected format ("Import-DscResource -ModuleName 'Microsoft365DSCCustomRes'") also works. https://github.com/microsoft/DSCParser/blob/d6c7f365fb91e697890755db376b3fb2ef420ad0/Modules/DSCParser/Modules/DSCParser.psm1#L325-L326

FabienTschanz commented 2 months ago

@ssoabx Checking in to see if the issue is resolved with the latest release. Could you please check and report back? Thank you.

Also, could you share a minimal reproducible configuration example, so that we can have a look at it?