DEV Community

Cover image for How to import (many) modules into Azure Automation | Command Line | en-us
Ewerton Jordão
Ewerton Jordão

Posted on • Edited on

1

How to import (many) modules into Azure Automation | Command Line | en-us

How to import local modules into your automation service by command line.

Hy everyone, how are u? Bringing a cool tip for those who use the automation service available in Azure (Azure Automation). The import process via the graphical interface is intuitive and helps a lot when there is not much intimacy with the command line, but it becomes somewhat repetitive if you need to search for various modules and perform an import.

Sometimes, when we are developing some automation, we carry out local tests. And, often, it uses modules to help the tasks. If for some reason you have module numbers, how do you put that list in your automation account? I will demonstrate how to execute the process in the script below:

Import-Module -Name Az
[array]$lista = Get-Module -Name Az.* | Select name
foreach($item in $lista.Name){
New-AzAutomationModule -ResourceGroupName "<NomedoGrupoDeRecurso>" `
-AutomationAccountName "NomeDaContaDeAutomacao" `
-Name $item `
-ContentLinkUri "https://www.powershellgallery.com/api/v2/package/$item"
}
[array]$list = Get-Module -Name Az.* -ListAvailable | Select name
$i = 0
do {
Write-Host ("Import Module {0}" -f $list.item($i).Name)
New-AzAutomationModule -ResourceGroupName "<NomedoGrupoDeRecurso>" `
-AutomationAccountName "NomeDaContaDeAutomacao" `
-Name $list.item($i).Name `
-ContentLinkUri ("https://www.powershellgallery.com/api/v2/package/{0}" -f $list.item($i).Name)
$i++
if (($i % 5) -eq 0) {
Start-Sleep -Seconds 20
}
} until ($i -eq $list.Name.count)

⚠ When do you use the first script you can receive an error because the import-module on Azure Automation has a limited number of jobs simultaneously.

Creating Jobs in Azure using a connection created in the Visual Studio Code terminal. Connect-AzAccount

Visualization of module import jobs in the Azure portal with import status

Visualization of the module import jobs in the Azure portal with the status of available from this moment we can use the modules in the scripts

After all modules are finished importing, we can use them in our PowerShell runbooks, without any problem of failing due to lack of any reference.

That's it, folks. Don't forget, PWSH + Azure Automation is life

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay