为什么Azure Powershell脚本认为我没有登录?

时间:2016-12-14 11:35:22

标签: powershell azure azure-powershell

我正在构建一个Azure Powershell脚本来添加数据库防火墙规则。

我首先login using Add-AzureRmAccount

$userName = "j---@s---.--"
$securePassword = ConvertTo-SecureString -String "---------" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential($userName, $securePassword)
Add-AzureRmAccount -Credential $cred

这将返回以下内容,我认为这意味着我已成功登录:

Environment           : AzureCloud
Account               : j---@s---.--
TenantId              : [GUID]
SubscriptionId        : [GUID]
SubscriptionName      : Visual Studio Ultimate mit MSDN
CurrentStorageAccount : 

在此阶段,我可以查询我的订阅:

Get-AzureRmSubscription –SubscriptionName "Visual Studio Ultimate mit MSDN" | Select-AzureRmSubscription

返回

Account      : j---@s---.--
Environment  : AzureCloud
Subscription : [GUID]
Tenant       : [GUID]

到目前为止,非常好。

但是,只要脚本调用资源组级别的任何内容,例如

Find-AzureRmResource -ResourceNameContains "-----NorthEurope"

然后用

回应
  

运行Login-AzureRmAccount登录。

例外细节是

  

+ CategoryInfo:InvalidOperation:(:) [Find-AzureRmResource],PSInvalidOperationException

     

+ FullyQualifiedErrorId:InvalidOperation,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.FindAzureResourceCmdlet

这对我没有任何帮助。

我甚至明确地打电话给

Login-AzureRmAccount $cred
Find-AzureRmResource电话会议之前

,但这没有任何区别。

当然,我最终要做的就是打电话

New-AzureRmSqlServerFirewallRule    -ResourceGroupName "-----NorthEurope" `
                                    -ServerName "-----.database.windows.net" `
                                    -FirewallRuleName "test1" `
                                    -StartIpAddress "-.-.-.-" `
                                    -EndIpAddress "-.-.-.-"

但是遇到了同样的例外。

有人可以解释为什么我显然成功添加帐户后会被要求运行Login-AzureRmAccount吗?

解决方案

正如@Tomer在评论中提到的那样,对我有用的是强行重新获取所有AzureRm模块。

0 个答案:

没有答案