2 minute read

There are a number of methods to import PowerShell modules into Azure automation as described in the documentation here

You may however miss an important piece of information hidden in that documentation if you are uploading a module from a GitHub release instead of via the PowerShell Gallery. The name that you refer to the module must match the module name and module folder name in the zip file.

Method one - from Gallery

This is my preferred method for importing modules into Azure Automation accounts, the only bothersome part is remembering to do it twice, once for 5.1 and once for 7.1 as I am sure that if I forget that will be the one module that I will need!

Find the module

Go to the Module page for the automation account and then Add module and browse the gallery and search for dbatools (other modules are available!) and install it

image

It will take a few moments to install but you will see it in the list with a green tick once it has imported.

image#

Then it is available in all of my PowerShell 7.1 runbooks in my automation account - Here I have just run Get-DbaToolsConfig in a test runbook to prove that the module has imported

image

Method two - using the zip file from a GitHub Release

Sometimes you may wish to not use the PowerShell Gallery to import the modules, maybe you have a custom module that you are not ready to upload to the gallery or maybe the module is just internally developed and not available on the PowerShell Gallery. In this scenario, you can still import hte module so that it can be used by your runbooks.

To demonstrate, I will remove the dbatools module from the Automation Account

image

and download the latest release from GitHub directly

https://github.com/dataplat/dbatools/releases/tag/v1.1.118

If you are unable to use the PowerShell Gallery to get the latest dbatools release, I would always use the official signed release.

You can then upload the zip from the same Modules page using the Browse for file but here is the important bit You must update the name of the module. By default Azure will set the name to match the name of the zip file as that is what is expected and indeed mentioned in the Microsoft documentation here

image

and once it is imported successfully and I have a green tick

image

I can run the test - Again I just ran Get-DbaToolsConfig

image

This method will work with both PowerShell 5.1 and PowerShell 7.1, you will just have to upload the zip (and remember to rename the module entry) twice.

image

image

When it goes wrong

If you do not rename the module correctly but leave it as the name of file dbatools-signed in this example

image .

image

Error importing the module dbatools-signed. Import failed with the following error:
Orchestrator.Shared.AsyncModuleImport.ModuleImportException: Cannot import the module of name dbatools-signed, 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)

If you get that, just re-upload the zip file and use the correct name in the form.

Happy Automating

Comments