【发布时间】:2018-03-07 18:29:26
【问题描述】:
更新:
好像其他人也有同样的问题,reported 它。
从 Azure 自动化 Runbook 调用简单的 PowerShell 脚本时,我遇到了问题。同一段代码在本地运行时完美无缺。
我在 Azure Active Directory(托管在 Azure German Cloud 中)中添加了一个服务主体,并带有密码凭据,并授予它贡献者对订阅的访问权限(也托管在Azure 德国云)。
Azure 自动化服务托管在 北欧,因为它目前在 Azure German Cloud 中不可用。
我要做的就是使用Add-AzureRmAccount cmdlet 使用上述主体登录我的订阅。之后我尝试使用Set-AzureRmContext 设置当前上下文并收到以下错误消息:
Set-AzureRmContext : Please provide a valid tenant or a valid subscription.
At line:26 char:1
+ Set-AzureRmContext -TenantId $TenantId -Su ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Set-AzureRmContext], ArgumentException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.SetAzureRMContextCommand
这是我尝试运行的脚本(将配置留空):
$TenantId = ""
$ApplicationId = ""
$ClientSecret = ""
$SubscriptionId = ""
$secpasswd = ConvertTo-SecureString $ClientSecret -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ($ApplicationId , $secpasswd)
Add-AzureRmAccount -ServicePrincipal -Environment 'AzureGermanCloud' -Credential $mycreds -TenantId $TenantId
Set-AzureRmContext -TenantId $TenantId -SubscriptionId $SubscriptionId
我也尝试使用Login-AzureRmAccount,但没有成功。我还可以使用Get-AzureRmResourceGroup cmdlet 来检索资源组,因此登录似乎可以正常工作。
所有 Azure 模块都更新到最新版本。
TLTR:
我的主要目标是使用 runnbook 中的 New-AzureRmSqlDatabaseExport 启动 SQL 导出作业,但似乎上述错误会导致 cmdlet 失败并显示以下消息:
New-AzureRmSqlDatabaseExport : Your Azure credentials have not been set up or have expired, please run
Login-AzureRMAccount to set up your Azure credentials.
At line:77 char:18
+ ... rtRequest = New-AzureRmSqlDatabaseExport -ResourceGroupName $Resource
【问题讨论】:
-
如果登录有效,为什么需要
set-azurermcontext?只需将-SubscriptionId添加到add-azurermaccount -
@4c74356b41 因为
New-AzureRmSqlDatabaseExport仍然会抛出该异常。我试图提供一个最小的例子来重现我的问题,我认为Set-AzureRmContext不起作用的答案将帮助我实现我的主要目标。 -
为什么还要这样做?
-
@4c74356b41 如果我知道我不会问这个问题。我已经试过了。此外,当我尝试使用带有
-SubscriptionId和-TenantId参数的Get-AzureRmSubscription获取订阅时,我收到消息Subscription xxx was not found in tenant -
租户 ID 或订阅 ID 错误?
标签: powershell azure azure-automation azure-mcd