How to list all running webjobs within an azure subscription using powershell

后端 未结 2 856
温柔的废话
温柔的废话 2020-12-21 14:33

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

2条回答
  •  爱一瞬间的悲伤
    2020-12-21 15:36

    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 <>
    Get-AzureRmContext
    
    Add-AzureAccount
    Select-AzureSubscription -SubscriptionId <>
    Get-AzureSubscription -Current
    

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

提交回复
热议问题