【发布时间】:2015-06-04 18:31:08
【问题描述】:
我正在尝试创建 Azure 自动化作业以在订阅中创建一组标准的标签/值。
使用标签需要 AzureResourceManager,而自动化中没有开箱即用的 AzureResourceManager(去投票给这个feedback item!),所以我跟着these steps 上传了 ARM 模块。
当我测试我的运行手册时,我得到以下输出:
-------------------------
PSComputerName : localhost
PSSourceJobInstanceId : a8b85213-ee0f-40ea-842f-d33f2e87c910
Id : xxxxx-56ad-42c2-97f4-e364456fc4a6
Name : xxxxx
Environment : AzureCloud
Account : my-service-principal-app-id
Properties : {Default, Tenants, SupportedModes}
-------------------------
New-AzureTag : Your Azure credentials have not been set up or have expired, please run Add-AzureAccount to set up your
Azure credentials.
At Add-SubscriptionTags:41 char:41
+
+ CategoryInfo : CloseError: (:) [New-AzureTag], ArgumentException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Tags.Tag.NewAzureTagCommand
这是我的运行手册:
workflow Add-SubscriptionTags
{
param
(
# Subscription
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]
$SubscriptionName
)
# Get the PowerShell credential and prints its properties
$cred = Get-AutomationPSCredential -Name 'AzureMaint'
# Connect to Azure
Add-AzureAccount -Credential $cred -ServicePrincipal -Tenant 'xxx-49ab-8a9c-4abce32afc1e' | Write-Verbose
# Set subscription
$subscription = Select-AzureSubscription -SubscriptionName $SubscriptionName -PassThru
write-output '-------------------------'
write-output $subscription
write-output '-------------------------'
# Add tags (Requires AzureResourceManager module)
New-AzureTag -Name 'Managed' -Value $true
New-AzureTag -Name 'Managed' -Value $false
}
AzureMaint PSCredential 包含服务主体 ID 和密钥,并且服务主体已被授予指定订阅的参与者角色。我可以使用这些凭据在 ISE 中执行 Add-AzureAccount 并添加标签就好了。既然它成功打印了订阅信息,我认为这意味着Add-AzureAccount 是成功的,那么为什么我会收到错误消息?
更新:
我创建了一个没有 ARM 模块的新自动化帐户,但我仍然遇到同样的问题,尽管错误消息略有不同:
Your Azure credentials have not been set up or have expired, please run Add-AzureAccount
to set up your Azure credentials. (Your Azure credentials have not been set up or
have expired, please run Add-AzureAccount to set up your Azure credentials. (Unable
to retrieve service key for ServicePrincipal account xxx-4a00-becf-952fda93edc5.
Please run the Add-AzureAccount cmdlet to supply the credentials for this service principal.))
所以现在我想知道它是否不喜欢我使用服务主体?
【问题讨论】:
-
Azure 模块不支持服务主体进行身份验证,只有 ARM 模块支持。在 Azure 自动化之外,PowerShell ISE 中的 Azure 模块应该有同样的问题。