【发布时间】:2021-05-16 05:56:36
【问题描述】:
我有一个我想通过 azure 自动化帐户运行的 powershell 脚本。该脚本在 cloudshell 上运行时运行良好,但通过 powershell runbook 运行时,它没有执行预期的任务并引发错误。当我使用 Select-AzSubscription -SubscriptionName 'xxx' 时,它告诉我使用 Connect-AzAccount,当我使用它给我的找不到打开的端口错误。 有人能帮忙吗?我列出了我收到的四种不同的错误消息。
Connect-AzAccount : Cannot find an open port. At line:6 char:1 + Connect-AzAccount + ~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Connect-AzAccount], Exception + FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand
Get-AzVM : Argument passed in is not serializable. Parameter name: value At line:19 char:12 + $vmOSDisk=(Get-AzVM -ResourceGroupName $resourceGroupName -Name $vmNa ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Get-AzVM], ArgumentException + FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.GetAzureVMCommand
New-AzStorageContext : Context cannot be null. Please log in using Connect-AzAccount. At line:50 char:23 + ... onContext = New-AzStorageContext -StorageAccountName $destinationstor ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [New-AzStorageContext], InvalidOperationException + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.Storage.Common.Cmdlet.NewAzureStorageContext
Start-AzStorageBlobCopy : Cannot bind argument to parameter 'AbsoluteUri' because it is null. At line:55 char:38 + Start-AzStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer $d ... + ~~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Start-AzStorageBlobCopy], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.WindowsAzure.Commands.Storage.Blo [![enter image description here][1]][1]b.Cmdlet.StartAzureStorageBlobCopy
这里是部分代码的片段供参考。脚本中使用了 Az 模块,并且默认情况下新的 Azure 自动化帐户没有安装 Az 模块,即使在导入 Az.Accounts、Az.Automation、Az.Compute 之后我也会收到这些错误。
【问题讨论】:
-
您通过 Connect-AzAccount 发送哪些参数?为您用于 sigh-in 的帐户启用了 MFA?
-
为了人类的爱,请将您的代码发布为纯文本,而不是屏幕截图 - 最好是生成列出的错误的实际代码
-
投票作为答案的脚本是我正在使用的代码。它在云 shell 上运行良好,但在 Azure 自动化帐户运行手册上运行不正常。
-
@OlehTarasenko 我没有通过 Connect-AzAccount 传递任何参数,并且我登录的帐户没有启用任何 MFA。
标签: azure powershell azure-automation azure-runbook