question

Nibbler avatar image
0 Votes"
Nibbler asked Nibbler commented

Azure Autimation - Powershell script failing

Hi all,

I have the following PS script, that I want schedule using Azure Automation, is failing saying that "Set-AzureRmAppServicePlan" is not correct. That I dont understand as it works geat when running it in Azure Cloud Shell


Set-AzureRmAppServicePlan -Name "Solution-EUWE" -ResourceGroupName "Shared" -Tier PremiumV2 -NumberofWorkers 1 -WorkerSize "Small"

The error:
Set-AzureRmAppServicePlan : The term 'Set-AzureRmAppServicePlan' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + Set-AzureRmAppServicePlan -Name "Solution-EUWE" -ResourceGroupName " ... + ~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Set-AzureRmAppServicePlan:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

windows-server-powershellazure-automation
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

AndreasBaumgarten avatar image
0 Votes"
AndreasBaumgarten answered Nibbler commented

Hi @KE1980 ,

the cmdlet Set-AzureRmAppServicePlan is part of the AzureRM.Websites module.
This module is not imported in an Azure Automation Account by default.

Please try the following steps:

In the Azure Portal ...

83235-image.png


Import the module ...


83216-image.png


Now the runbook should work.


(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

Regards
Andreas Baumgarten



image.png (203.0 KiB)
image.png (79.6 KiB)
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks @AndreasBaumgarten

I found the module, as you describe, but getting a:

This module has dependencies that are not present in this account. All dependencies must be present before this module can be imported.
Dependencies:
AzureRM.Profile (≥ 5.8.4)

That I have to look into before its possible, it seems.

1 Vote 1 ·

The AzureRM.Websites has a dependency to the AzueRM.Profile module.

Unfortunately dependencies are not resolved automatically. You have to import dependent modules manually ... which can be a little work because the dependent modules could have dependencies as well.
But at the end it should work ;-)


(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

Regards
Andreas Baumgarten

1 Vote 1 ·
Nibbler avatar image Nibbler AndreasBaumgarten ·

Thanks @AndreasBaumgarten

Yeah, I have imported all the needed modules, but things keep popping up....MS have realy made it a trip using their automation.... So, now its complaining about not having found a subscritpion. Havent found any useable doc`s or exsamples on how to solve this... dont understand the need for this as one is already logged in to the sub etc.



Set-AzureRmAppServicePlan : No subscription found in the context. Please ensure that the credentials you provided are authorized to access an Azure subscription, then run Connect-AzureRmAccount to login. At line:1 char:1 + Set-AzureRmAppServicePlan -Name "Solution1" -ResourceGroupName " ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Set-AzureRmAppServicePlan], ApplicationException + FullyQualifiedErrorId : Microsoft.Azure.Commands.WebApps.Cmdlets.AppServicePlans.SetAzureAppServicePlanCmdlet

0 Votes 0 ·

Hi @KE1980 ,

maybe this is helpful:
https://hacksbyme.net/2019/04/03/use-azure-automation-to-scale-you-azure-resources/


(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

Regards
Andreas Baumgarten

0 Votes 0 ·
Show more comments