I am using and edited version of the script in the first answer on this question. I first login, select the appropriate subscription, then get the Azure Rm Context. I get this error when I do this:
Get-AzureWebsiteJob : No default subscription has been designated. Use Select-AzureSubscription -Default to set the default subscription.
The script:
Login-AzureRmAccount
Select-AzureRmSubscription -SubscriptionId subidguid
Get-AzureRmContext
$groups = get-AzureRmResourceGroup
foreach($group in $groups){
$webApps = Get-AzureRmWebApp -ResourceGroupName $group.ResourceGroupName
foreach($webApp in $webApps){
write-host -ForegroundColor Yellow $webApp.Name
### ERROR HAPPENS
$job = Get-AzureWebsiteJob -Name $webApp.Name
if($job){
write-host -ForegroundColor DarkYellow $job.JobName
}
$job = Get-AzureWebsiteJob -Name $webApp.Name -Slot staging
if($job){
write-host -ForegroundColor DarkYellow $job.JobName " -staging"
}
}
}
I do get the names of the web apps outputted on the screen, but when it looks for webjobs, I get that error. I tried the below technique based on the error, but this didn't help (edited the full code to make it clear what changes I made even though I still got the same error):
Login-AzureRmAccount
Select-AzureRmSubscription -SubscriptionId subidguid
Get-AzureRmContext
$groups = get-AzureRmResourceGroup
foreach($group in $groups){
$webApps = Get-AzureRmWebApp -ResourceGroupName $group.ResourceGroupName
foreach($webApp in $webApps){
write-host -ForegroundColor Yellow $webApp.Name
### ERROR HAPPENS
Select-AzureRmSubscription -SubscriptionId subidguid
$job = Get-AzureWebsiteJob -Name $webApp.Name
if($job){
write-host -ForegroundColor DarkYellow $job.JobName
}
### ERROR HAPPENS
Select-AzureRmSubscription -SubscriptionId subidguid
$job = Get-AzureWebsiteJob -Name $webApp.Name -Slot staging
if($job){
write-host -ForegroundColor DarkYellow $job.JobName " -staging"
}
}
}
Essentially, before getting the web job details, I am first selecting the subscription id (shortened):
Select-AzureRmSubscription -SubscriptionId subidguid
$job = Get-AzureWebsiteJob -Name $webApp.Name
Executing ...
Select-AzureRmSubscription -Default -SubscriptionId subguidid
Throws a different error:
Set-AzureRmContext : Missing an argument for parameter 'DefaultProfile'. Specify a parameter of type 'Microsoft.Azure.Commands.Common.Authentication.Abstractions.IAzureContextContainer' and try again.
I've tried using the DefaultProfile
parameter instead of Default
. Regardless of what I pass in using Default
, I get the error:
Set-AzureRmContext : Cannot bind parameter 'DefaultProfile'. Cannot convert the "WhatYouEntered" value of type "System.String" to type "Microsoft.Azure.Commands.Common.Authentication.Abstractions.IAzureContextContainer".
I still get the same error. When I look at the parameters allowed in the function of Get-AzureWebsiteJob
, I don't see an option to specify the subscription. Given that the jobs should be searched for by web apps, and the web apps return, why does this not find it by subscription id here?