4

I have an azure subscription that has upwards of 200 appServices where around about half of them have Continuous, always on webJobs attached, some also have slots which also have webJobs.

Is there a way to list all webJobs that are inside a subscription? I was originally tring to use powershell to do this but it was getting rather complex and was wondering if anyone knew of an easy way to achieve the above.

It seems like Get-AzureRmWebApp should be able to help but i cant find a way to list the jobs that reside inside the webapps.

Damo
  • 5,698
  • 3
  • 37
  • 55

4 Answers4

7

I found the command Get-AzureWebsiteJob which is not in the AzureRM family of commandlets. The following script can get the data that I'm looking for:

$groups = get-AzureRmResourceGroup | where{$_.ResourceGroupName -like "*-prod-*"}

foreach($group in $groups){
    Write-Host -ForegroundColor Cyan "processing resourceGroup" $group.ResourceGroupName

    $webApps = Get-AzureRmWebApp -ResourceGroupName $group.ResourceGroupName

    foreach($webApp in $webApps){
        write-host -ForegroundColor Yellow $webApp.Name        
        $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"
        }
    }
}

The above does not filter out the running ones from the stopped, but that can be easily added if need be.

Of course you firstly need to be logged into AzureRM and Azure classic

Login-AzureRmAccount
Select-AzureRmSubscription -SubscriptionId <<mySubscriptionId>>
Get-AzureRmContext

Add-AzureAccount
Select-AzureSubscription -SubscriptionId <<mySubscriptionId>>
Get-AzureSubscription -Current

Its a very slow script iterating over this number or AppServices though. Any ideas for speeding it up would be appreciated.

Damo
  • 5,698
  • 3
  • 37
  • 55
3

You can do it through the ARM APIs, though you still need to call it on each Web App.

You can get the WebJobs with a GET request to:

https://management.azure.com/subscriptions/subscription-id/resourceGroups/resource-group-name/providers/Microsoft.Web/sites/app-name/webjobs?api-version=2016-03-01

But I doubt this will be any more efficient than what you have since you still need to make a call for every Web App. And you will need to get the access token somehow.

Web Jobs are a property of App Service applications and can't be requested all at once from Azure.

juunas
  • 54,244
  • 13
  • 113
  • 149
0

I know it's too late but we can try with Azure CLI too these days.

az webapp webjob triggered list --name MyWebApp --resource-group MyResourceGroup

Additionally, you can query the above result and get the desired information you are looking for

az webapp webjob triggered list --name MyWebApp --resource-group MyResourceGroup  --query "[].{Name:name, Schedule:settings.schedule}"
EZR
  • 63
  • 6
0

I know it's too late but we can try with Azure CLI too these days.

az webapp webjob triggered list --name MyWebApp --resource-group MyResourceGroup

Additionally, you can query the above result and get the desired information you are looking for

az webapp webjob triggered list --name MyWebApp --resource-group MyResourceGroup  --query "[].{Name:name, Schedule:settings.schedule}"

But, again you have to run the above query in the for each loop to fetch the results from all resource groups in the subscription.

EZR
  • 63
  • 6