Azure automation account custom powershell module: Cannot import the module of name ModuleName, as the module structure was invalid

Bjørn Langeland 25 Reputation points
2024-09-19T12:29:34.4066667+00:00

Im trying to add a custom powershell module, but I get this error:

Orchestrator.Shared.AsyncModuleImport.ModuleImportException: Cannot import the module of name ModuleName, as the module structure was invalid. at Orchestrator.Activities.GetModuleMetadataAfterValidationActivity.ExecuteInternal(CodeActivityContext context, Byte[] moduleContent, String moduleName, ModuleLanguage moduleLanguage) at Orchestrator.Activities.GetModuleMetadataAfterValidationActivity.Execute(CodeActivityContext context) at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

The .zip im importing has the following structure:

ModuleName.zip

 -Config  
 -Private

 -Public  
 -ModuleName.psd1

 -ModuleName.psm1
Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,366 questions
0 comments No comments
{count} votes

Accepted answer
  1. Amira Bedhiafi 33,071 Reputation points Volunteer Moderator
    2025-05-27T18:56:27.9966667+00:00

    Hello Bjorn !

    Thank you for posting on Microsoft Learn.

    Inside the ZIP root, you must have a folder with the exact same name as the module, and inside that folder, the .psd1 and .psm1 files must reside, like so:

    ModuleName.zip
    │
    └───ModuleName\
        │   ModuleName.psd1
        │   ModuleName.psm1
        └───Private\
        └───Public\
        └───Config\
    

    Create a folder called ModuleName (exactly matching the module name) and ove ModuleName.psd1, ModuleName.psm1, and all subfolders (Private, Public, Config...) inside this folder.

    Then zip the folder so that the ZIP file root contains only the ModuleName folder.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.