具有订阅ID的Azure Powershell Select-AzureSubscription

Ahm*_*gle 6 powershell azure azure-powershell

我正在使用Powershell Azure cmdlet对我拥有的每个订阅执行一些操作.

但是,我的所有订阅都具有相同的名称.所以,如果我做一个像这样的操作:

$subs | ForEach-Object {
    Select-AzureSubscription -Current -SubscriptionName $_.SubscriptionName
    $services = Get-AzureService
    Write-Output "$($services .Length) services under $($_.SubscriptionId) subscription"
}
Run Code Online (Sandbox Code Playgroud)

它始终适用于相同的订阅,因为订阅仅在订阅ID方面有所不同.

而且Select-AzureSubscription没有-SubscriptionId参数.

任何想法如何找到解决方法?

Ric*_*los 8

不确定这是否在以后添加,但截至2015年11月,您可以使用 -SubscriptionId

Write-Host "Selecting Azure subscription using id"
Select-AzureSubscription -SubscriptionId $subscriptionId
Run Code Online (Sandbox Code Playgroud)


Dav*_*gon 1

编辑publishsettings 文件,为每个订阅指定不同的名称。然后重新导入。那时,您将能够通过名称轻松地访问每一个。