如何使用Powershell列出Azure订阅中的所有正在运行的

如何使用Powershell列出Azure订阅中的所有正在运行的

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

问题描述

我有一个Azure订阅,其中包含200个以上的appService,其中约有一半具有Continuous,并且始终在附连的webJob上,有些还具有也包含webJob的插槽.

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.

是否可以列出订阅中的所有webJob?我本来是想使用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似乎应该能够提供帮助,但我找不到列出该Webapp内作业的方法.

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 Commandlet系列中.以下脚本可以获取我要查找的数据:

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订阅中的所有正在运行的Webjob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 01:50