Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling of custom DSC resources in config #42

Open
ssoabx opened this issue Apr 4, 2024 · 1 comment
Open

Error handling of custom DSC resources in config #42

ssoabx opened this issue Apr 4, 2024 · 1 comment

Comments

@ssoabx
Copy link

ssoabx commented Apr 4, 2024

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

$DSCResources = @()
foreach ($moduleToLoad in $ModulesToLoad)
{
$loadedModuleTest = Get-Module -Name $moduleToLoad.ModuleName -ListAvailable | Where-Object -FilterScript {$_.Version -eq $moduleToLoad.ModuleVersion}
if ($null -eq $loadedModuleTest -and -not [System.String]::IsNullOrEmpty($moduleToLoad.ModuleVersion))
{
throw "Module {$($moduleToLoad.ModuleName)} version {$($moduleToLoad.ModuleVersion)} specified in the configuration isn't installed on the machine/agent. Install it by running: Install-Module -Name '$($moduleToLoad.ModuleName)' -RequiredVersion '$($moduleToLoad.ModuleVersion)'"
}
else
{
$currentResources = Get-DSCResource -Module $moduleToLoad.ModuleName
if (-not [System.String]::IsNullOrEmpty($moduleToLoad.ModuleVersion))
{
$currentResources = $currentResources | Where-Object -FilterScript {$_.Version -eq $moduleToLoad.ModuleVersion}
}
$DSCResources += $currentResources
}
}

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.

$moduleName = $statement.CommandElements[$i+1].Value
$currentModule.Add('ModuleName', $moduleName)

@ssoabx ssoabx changed the title Error handling of custom DSC resources in DSC config Error handling of custom DSC resources in config Apr 4, 2024
@FabienTschanz
Copy link
Contributor

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants