Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用powershell列出azure订阅中所有正在运行的WebJob_Powershell_Azure_Azure Web App Service_Azure Resource Manager - Fatal编程技术网

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

如何使用powershell列出azure订阅中所有正在运行的WebJob,powershell,azure,azure-web-app-service,azure-resource-manager,Powershell,Azure,Azure Web App Service,Azure Resource Manager,我有一个azure订阅,它有200多个appServices,其中大约一半有连续的、始终在线的webJobs,有些还有插槽也有webJobs 有没有办法列出订阅中的所有WebJob?我最初尝试使用powershell来实现这一点,但它变得相当复杂,我想知道是否有人知道实现上述目标的简单方法 似乎Get-AzureRmWebApp应该能够提供帮助,但我找不到列出驻留在WebApp中的作业的方法。我找到了Get-AzureWebsiteJob命令,该命令不在AzureRM Commandlet系列中

我有一个azure订阅,它有200多个appServices,其中大约一半有连续的、始终在线的webJobs,有些还有插槽也有webJobs

有没有办法列出订阅中的所有WebJob?我最初尝试使用powershell来实现这一点,但它变得相当复杂,我想知道是否有人知道实现上述目标的简单方法


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

我找到了Get-AzureWebsiteJob命令,该命令不在AzureRM Commandlet系列中。以下脚本可以获取我正在查找的数据:

$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"
        }
    }
}
上面的内容不会从停止的列表中过滤掉正在运行的列表,但是如果需要,可以很容易地添加这些列表

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

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

Add-AzureAccount
Select-AzureSubscription -SubscriptionId <<mySubscriptionId>>
Get-AzureSubscription -Current
登录AzureRmAccount
选择AzureRmSubscription-SubscriptionId
获取AzureRmContext
添加AzureAccount
选择AzureSubscription-SubscriptionId
获取AzureSubscription-当前

不过,在这个数字或AppServices上迭代的速度非常慢。如果您有任何加速的想法,我们将不胜感激。

您可以通过ARM API来实现,尽管您仍然需要在每个Web应用程序上调用它

您可以通过get请求获取WebJobs,以:

https://management.azure.com/subscriptions/subscription-id/resourceGroups/resource-group-name/providers/Microsoft.Web/sites/app-name/webjobs?api-version=2016-03-01
但我怀疑这会比你现有的更有效率,因为你仍然需要为每个Web应用打电话。您需要以某种方式获取访问令牌


Web作业是应用程序服务应用程序的属性,不能从Azure一次请求所有作业。

如果您的订阅仅支持基于RM的资源,则可能会遇到问题。