订阅中列出所有正在运行的

订阅中列出所有正在运行的

本文介绍了如何使用 powershell 在 azure 订阅中列出所有正在运行的 webjobs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 azure 订阅,其中有超过 200 个应用服务,其中大约一半有持续的,总是在附加的 webJobs 上,有些也有插槽,也有 webJobs.

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.

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

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.

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

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.

推荐答案

我发现了 Get-AzureWebsiteJob 命令,它不在 AzureRM 命令行开关系列中.以下脚本可以获取我要查找的数据:

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.

当然首先需要登录AzureRM和Azure经典版

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

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

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

这篇关于如何使用 powershell 在 azure 订阅中列出所有正在运行的 webjobs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 01:50