我已在Windows Server 2012 R2 build服务器上安装了64位专用代理。我已将此连接到Azure开发运营部。在构建服务器上,我只安装了AzureRM的5.6.0版本,因为这是我想要运行的脚本所必需的。如果您感兴趣,请参阅我的其他问题,了解原因:
How to set PITR for all databases in a Azure Sql Database Elastic Pool?
如果我在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.
如果我以build server帐户登录到build server,并打开PowerShell窗口,就可以了。它在Azure DevOps中的正常PowerShell任务中也可以正常工作。
我的PowerShell脚本需要在Azure帐户的上下文中运行,如何实现这一点?
编辑
我尝试了Azure PowerShell任务v1和v2,但都没有成功。我还尝试将版本选项部分中的PowerShell版本指定为5.6版,以及最新安装的版本。这两个都不管用。