Reputation: 21
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?
Upvotes: 2
Views: 1648
Reputation: 13954
For now, Azure classic web site move to Azure ARM module, we can't use Get-AzureWebsiteJob
to get web jobs.
There is no direct equivalent in the ARM PowerShell Cmdlets.
We can use this command to list web app jobs:
Get-AzureRmResource -ResourceGroupName $ResourceGroupName -ResourceName $AppService -ResourceType microsoft.web/sites/<Webjob-type> -ApiVersion $Apiversion
Here is an example:
$Apiversion = "2015-08-01"
Get-AzureRmResource -ResourceGroupName $ResourceGroupName -ResourceName jasonapp3 -ResourceType microsoft.web/sites/triggeredwebjobs -ApiVersion $Apiversion
Also we can use this command start or stop web jobs.
Invoke-AzureRmResourceAction -ApiVersion $Apiversion -ResourceGroupName $ResourceGroupName -ResourceName $ResourceName -ResourceType microsoft.web/sites/<Webjob-type> -Action start/stop -Force
Delete a webjob:
Remove-AzureRmResource -ApiVersion $Apiversion -ResourceGroupName $ResourceGroupName -ResourceName $ResourceName -ResourceType microsoft.web/sites/<Webjob-type>/<Webjob-name> -Force
Hope this helps.
Upvotes: 1
Reputation: 12768
Get-AzureWebsiteJob
is Azure Service Management PowerShell Module.
You need to use Add-AzureAccount
to use the following cmdlet.
Use this one to select your default subscription:
Select-AzureSubscription -Default -SubscriptionName "My Production (Pay-As-You-Go)"
You can also choose to use -SubscriptionId
(and the GUID) instead of the name.
For more information on the Select-AzureSubscription
commandlet; type Get-Help Select-AzureSubscription
.
If this doesn't work, try running first, before selecting your subscription:
Add-AzureAccount
For more details, refer "No default subscription has been designated. Use Select-AzureSubscription -Default <subscriptionName> to set the default subscription".
Upvotes: 1