如何使用 powershell 在 azure 订阅中列出所有正在运行的 webjobs

Dam*_*amo 2 powershell azure azure-resource-manager azure-web-app-service

我有一个 azure 订阅,其中有超过 200 个 appServices,其中大约一半有连续的,总是在附加的 webJobs 上,有些也有插槽,也有 webJobs。

有没有办法列出订阅中的所有 web 作业?我最初尝试使用 powershell 来执行此操作,但它变得相当复杂,并且想知道是否有人知道实现上述目标的简单方法。

似乎 Get-AzureRmWebApp 应该能够提供帮助,但我找不到列出驻留在 webapp 中的作业的方法。

Dam*_*amo 5

我找到了命令 Get-AzureWebsiteJob,它不在 AzureRM 的命令行开关系列中。以下脚本可以获得我正在寻找的数据:

$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"
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

上面没有从停止中过滤掉正在运行的,但是如果需要的话可以很容易地添加。

当然你首先需要登录AzureRM和Azure classic

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

Add-AzureAccount
Select-AzureSubscription -SubscriptionId <<mySubscriptionId>>
Get-AzureSubscription -Current
Run Code Online (Sandbox Code Playgroud)

不过,它是一个非常慢的脚本,它会遍历这个数字或 AppServices。任何加快速度的想法将不胜感激。