Azure: How to use custom module in State Configuration

100 Views Asked by At

I created a class based DSC Resource as a Powershell Module and successfully uploaded it to Azure Automation/Modules. It has a green icon and seems to be added successfully. Now I want to use this module in State Configuration file. So I created configuration like this:

Configuration Temp01 {

    Import-DscResource -ModuleName 'MyModule' -ModuleVersion 1.0.0

    Node 'localhost' {
      MyResource Test01 {
          Param = ...
      }
    }

}

compiling this configuration on Azure

enter image description here

fails with error:

Exception calling "NewScriptBlock" with "1" argument(s): "At line:3 char:5 + Import-DscResource -ModuleName 'MyModule' -ModuleVersion 1. ... +
~~~~~~~ Could not find the module '<MyModule, 1.0.0>'." (At line:3 char:5 + Import-DscResource -ModuleName 'MyModule' -

What should I do ? How I could use my custom module in State Configuration ?

1

There are 1 best solutions below

3
Jahnavi On

After a workaround on your issue, the process and configuration set up you have followed is good to me. Check below points that might be the cause of the conflicts.

  • Check that the module has been uploaded completely and also check that the version of the module you are uploading is matches with the DSC configuration modules.
  • ModuleVersion property matches the version you are specifying in your configuration and Azure Automation modules.
  • Import the nx module along with your mymodule. It must be imported to compile the DSC resources if you are using PowerShell gallery. Refer MSDoc for more relevant information.

enter image description here

  • Make sure that the path of the located module is appropriately given. Instead of passing module name directly, provide the path of the module as shown.

Import-Module -Name 'C:\path\Module.psd1' -ModuleVersion 1.0.0

  • Verify the correct module version is available on the target nodes as you are using Automation account on VM's.
  • Also go to Virtual machine >> Extensions + applications >> Check the version is matching with your uploaded version.

enter image description here

  • If still the issue persists, use Set-DscLocalConfigurationManager command before importing the DSC resource to apply LCM settings prior with the required version.