Not possible to add a runbook from the PowerShell Gallery using PowerShell
Hi,
At the moment I'm Automating workloads in Azure. In a powershell script I want to add an Automation Account to an Azure subscription. Part of the Automation Account are Runbooks. You can add a runbook to Azure Automation by creating a new one or by importing an existing runbook from a file or the Runbooks Gallery. To Import a Runbook you can use the script down below.
$automationAccountName = "AutomationAccount"
$runbookName = "SampleTestRunbook"
$scriptPath = "C:\Runbooks\SampleTestRunbook.ps1"
$RGName = "ResourceGroup"
Import-AzureRMAutomationRunbook -Name $runbookName -Path $scriptPath
-ResourceGroupName $RGName -AutomationAccountName $automationAccountName
-Type PowerShellWorkflow
With the Import-AzureRMAutomationRunbook command you're not allowed to add a Runbook from the Runbook gallery or the PowerShell gallery. This is only possible from a local file. In the is Azure portal it's possible to import Runbooks from the PowerShell Gallery.
If you import an Azure Module you can use the script down below:
New-AzureRmAutomationModule -Name <ModuleName> -ContentLinkUri <ModuleUri> -ResourceGroupName <ResourceGroupName> -AutomationAccountName <AutomationAccountName>
In the ContentLinkUri part you can add a module from the PowerShell gallery.
Is there any solution to add a runbook using PowerShell from the PowerShell Gallery instead of a local file?
Thanks for your time reading this and your help.

Thanks for the valid suggestion. Your feedback is now open for the user community to upvote & comment on. This allows us to effectively prioritize your request against our existing feature backlog and also gives us insight into the potential impact of implementing the suggested feature.
2 comments
-
Ekelmans, Theo commented
If you are creating an automation account from an Azure pipeline using a PowerShell script it gets even worse, as there is no local path to import the Powershell files for the runbooks.
I therefore would suggest that Import-AzAutomationRunbook needs a parameter to "import" the scripts from the repo directly when creating the runbook.
-
Ken Knight commented
of course these suggestions are for *-Az* now vs *-AzureRM*