WPFUser
WPFUser

Reputation: 403

Running a powershell script involving AzureRM as an Azure webjob

I have very little experience using powershell, so this might be an obvious question.

I am trying to run a powershell script as a webjob. The scripts only purpose is to refresh an endpoint through AzureRM library.

I have managed to do this locally and it looks something like this:

Install-Module AzureRM -AllowClobber Import-Module AzureRM

Login-AzureRmAccount -ServicePrincipal -ApplicationId  "http://my-app"
-Credential $pscredential -TenantId $tenantid

$wsd = Get-AzureRmMlWebService -Name 'serviceName' -ResourceGroupName 'resourceGroupName' 
Update-AzureRmMlWebService -Name 'serviceName' -ResourceGroupName 'resourceGroupName' -ServiceUpdates $wsd

I need to be able to run this script on command from my website, so I figured creating a webjob for it was the way to go. However, the powershell that is running my script on the webjob side does not seem to have "install-module", nor AzureRM and so I feel a bit stuck. I tried attaching AzureRM to it, but there is a 50 mb limit and AzureRM is 500+ (100+ zipped).

[10/30/2017 19:37:46 > 44bf8a: ERR ] Install-Module : The term 'Install-Module' is not recognized as the name of a 
[10/30/2017 19:37:46 > 44bf8a: ERR ] cmdlet, function, script file, or operable program. Check the spelling of the 
[10/30/2017 19:37:46 > 44bf8a: ERR ] name, or if a path was included, verify that the path is correct and try again.

How should I go about this?

Also bonus question: How do I treat login in the webjob? Do I have to pass my live id credentials?

Upvotes: 1

Views: 864

Answers (1)

4c74356b41
4c74356b41

Reputation: 72171

Just to convert a comment to answer + give you a better idea how Azure works.

Everything is a REST API call in Azure. If you can do something in Azure (or portal can, or you saw it in some demo) - there is a REST call for that. It might or might not be documented, that's another thing (think demo\preview features that are not yet documented, or deprecated things already not documented but existing).

But in your case everything is really simple, you can do this from you local machine:

 Update-AzureRmMlWebService -Name 'serviceName' -ResourceGroupName 'resourceGroupName' -ServiceUpdates $wsd -Debug

With the -debug switch it will show you the REST call its performing and the answer it got (along with a lot of other information). That is a good way of learning how different Azure REST calls work. This works for any Azure Powershell cmdlets ;). Obviously (or not so obviously), you can do the same with Azure Portal using fiddler.

Upvotes: 1

Related Questions