Azure devops 术语';获取AzureRmPolicyDefinition';无法识别为cmdlet、函数、脚本文件或可操作程序的名称

Azure devops 术语';获取AzureRmPolicyDefinition';无法识别为cmdlet、函数、脚本文件或可操作程序的名称,azure-devops,azure-pipelines,azure-pipelines-release-pipeline,Azure Devops,Azure Pipelines,Azure Pipelines Release Pipeline,我对上一个任务有问题,分配策略: 应该已经包括包含资源命名空间(带有Get-AzureRmPolicyDefinition)的模块AzureRM,对吗? 那么我为什么会有这个错误消息呢 术语“Get-AzureRmPolicyDefinition”不能识别为cmdlet、函数、脚本文件或可操作程序的名称。请检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试 当我添加到PowerShell任务行时: 安装PackageProvider-Name NuGet-Force-Scope

我对上一个任务有问题,分配策略:

应该已经包括包含资源命名空间(带有Get-AzureRmPolicyDefinition)的模块AzureRM,对吗?

那么我为什么会有这个错误消息呢

术语“Get-AzureRmPolicyDefinition”不能识别为cmdlet、函数、脚本文件或可操作程序的名称。请检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试

当我添加到PowerShell任务行时:

安装PackageProvider-Name NuGet-Force-Scope CurrentUser

安装模块-名称Az.Accounts-所需版本1.6.2-强制-范围CurrentUser-AllowClobber

安装模块-名称AzureRM.Resources-必需版本6.7.3-强制-范围CurrentUser-AllowClobber

最后我会得到:

程序集“Microsoft.Azure.Commands.ResourceManager.Common,Version=4.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35”中类型为“Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient”的方法“get_SerializationSettings”没有实现

如何处理这个问题

2020-01-23T12:42:46.1108266Z ##[section]Starting: Assign Azure Policy
2020-01-23T12:42:46.1190930Z ==============================================================================
2020-01-23T12:42:46.1191016Z Task         : Azure PowerShell
2020-01-23T12:42:46.1191088Z Description  : Run a PowerShell script within an Azure environment
2020-01-23T12:42:46.1191160Z Version      : 4.159.7
2020-01-23T12:42:46.1191219Z Author       : Microsoft Corporation
2020-01-23T12:42:46.1191280Z Help         : [Learn more about this task](https://go.microsoft.com/fwlink/?LinkID=613749)
2020-01-23T12:42:46.1191368Z ==============================================================================
2020-01-23T12:42:48.5385840Z ##[command]Import-Module -Name C:\Modules\az_3.1.0\Az.Accounts\1.6.4\Az.Accounts.psd1 -Global
2020-01-23T12:42:50.3192937Z ##[warning]Both Az and AzureRM modules were detected on this machine. Az and AzureRM modules cannot be imported in the same session or used in the same script or runbook. If you are running PowerShell in an environment you control you can use the 'Uninstall-AzureRm' cmdlet to remove all AzureRm modules from your machine. If you are running in Azure Automation, take care that none of your runbooks import both Az and AzureRM modules. More information can be found here: https://aka.ms/azps-migration-guide
2020-01-23T12:42:55.2184342Z ##[command]Clear-AzContext -Scope Process
2020-01-23T12:42:56.2685211Z ##[command]Clear-AzContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue
2020-01-23T12:42:56.8285933Z ##[command]Connect-AzAccount -ServicePrincipal -Tenant *** -Credential System.Management.Automation.PSCredential -Environment AzureCloud
2020-01-23T12:42:57.9191448Z ##[command] Set-AzContext -SubscriptionId 78afced4-1c58-4e66-8242-c042890d34c3 -TenantId ***
2020-01-23T12:42:58.5652039Z ##[command]& 'D:\a\_temp\743dfd85-b908-48ee-9a00-e0ee97b44c8a.ps1' 
2020-01-23T12:42:59.9241324Z ##[command]Disconnect-AzAccount -Scope Process -ErrorAction Stop
2020-01-23T12:43:00.1484807Z ##[command]Clear-AzContext -Scope Process -ErrorAction Stop
2020-01-23T12:43:00.6509257Z ##[error]Method 'get_SerializationSettings' in type 'Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient' from assembly 'Microsoft.Azure.Commands.ResourceManager.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.
2020-01-23T12:43:00.6856188Z ##[section]Finishing: Assign Azure Policy

日志中的警告显示了导致以下问题的原因:

在此机器上检测到Az和AzureRM模块。阿兹和 AzureRM模块不能在同一会话中导入或在中使用 相同的脚本或运行手册。如果您在一个应用程序中运行PowerShell 您控制的环境可以使用“Uninstall-AzureRm”cmdlet 从计算机中删除所有AzureRm模块

不确定以前任务中的脚本是什么。但基于此错误消息,我可以确定的是它已将
AzureRm
模块安装到工作区中。因此,
AzureRM
模块在后面的步骤中与
Az
模块冲突

Az
模块是我们开发的新模块,用于取代
AzureRm
模块。但是当您将
AzureRm
Az
模块安装到一个工作区时,很容易导致错误



共享的脚本没有错误,因此只需在脚本之前运行
Uninstall AzureRm
,以避免此cmdlet冲突。

您说得对,这些模块不能同时安装。我还想分享我如何解决这个问题的信息:我找到了一个缺少命令的重新打包(对于task Assign Policy v4),并使用`Get-AzPolicyDefinition
(而不是获取AzureRmPolicyDefinition
新AzureRmPolicyAssignment-AssignIdentity-Location locationName
以使其正常工作。@Gajush,很高兴知道您找到了替换项!我看到这些替换命令都属于Az模块。感谢您分享该方法。)od你曾经在这里作为答案解决:-)伟大的工作…通过许多文件和网站…但没有使用…你简短的解释,解释更多的人…谢谢。。。