0

我在我的 Windows Server 2012 R2 构建服务器上安装了一个 64 位私有代理。我已将此连接到 Azure Dev Ops。在构建服务器上,我只安装了 5.6.0 版 AzureRM,因为这是我要运行的脚本所必需的。如果您有兴趣,请参阅我的另一个问题:如何为 Azure Sql 数据库弹性池中的所有数据库设置 PITR?

如果我在 Azure DevOps 中创建一个 Azure PowerShell v3 任务来运行以下内联脚本:

Get-Module -Name AzureRM* -ListAvailable

我收到此错误:

2018-11-14T13:26:56.0519566Z ==============================================================================
2018-11-14T13:26:56.0519655Z Task         : Azure PowerShell
2018-11-14T13:26:56.0519727Z Description  : Run a PowerShell script within an Azure environment
2018-11-14T13:26:56.0519782Z Version      : 3.1.7
2018-11-14T13:26:56.0519844Z Author       : Microsoft Corporation
2018-11-14T13:26:56.0520315Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=613749)
2018-11-14T13:26:56.0520404Z ==============================================================================
2018-11-14T13:26:57.1508635Z Added TLS 1.2 in session.
2018-11-14T13:26:57.4439615Z ##[command]Import-Module -Name C:\Program Files\WindowsPowerShell\Modules\AzureRM\5.6.0\AzureRM.psd1 -Global
2018-11-14T13:26:58.6759005Z ##[error]The following error occurred while loading the extended type data file: Error in TypeData "Microsoft.Azure.Commands.Common.Authentication.Abstractions.IAzureContextContainer": The TypeConverter was ignored because it already occurs.
Error in TypeData "Microsoft.Azure.Commands.Common.Authentication.Abstractions.IAzureContextContainer": The member SerializationDepth is already present.
Error in TypeData "Microsoft.Azure.Commands.Common.Authentication.ProtectedFileTokenCache": The member PropertySerializationSet is already present.
Error in TypeData "Microsoft.Azure.Commands.Common.Authentication.ProtectedFileTokenCache": The member SerializationMethod is already present.
Error in TypeData "Microsoft.Azure.Commands.Common.Authentication.AuthenticationStoreTokenCache": The member PropertySerializationSet is already present.
Error in TypeData "Microsoft.Azure.Commands.Common.Authentication.AuthenticationStoreTokenCache": The member SerializationMethod is already present.
Error in TypeData "Microsoft.Azure.Commands.Profile.Models.PSAzureContext": The member SerializationDepth is already present.
Error in TypeData "Microsoft.Azure.Commands.Profile.Models.PSAzureProfile": The member SerializationDepth is already present.

如果我以构建服务器帐户的身份登录构建服务器并打开一个 PowerShell 窗口,它工作正常。它在 Azure DevOps 中的普通 PowerShell 任务中也能正常工作。

我的 PowerShell 脚本需要在 Azure 帐户的上下文中运行,我该如何实现?

编辑

我已经尝试过 Azure PowerShell 任务 v1 和 v2,但没有成功。我还尝试将版本选项部分中的 PowerShell 版本指定为 5.6 版以及最新安装的版本。这些都不起作用。

4

0 回答 0