更新 Azure Powershell 模块后无法再导入我的模块并出现奇怪的错误

After updating Azure Powershell module cannot import my module anymore and getting strange error

我刚刚更新到最新的 Azure powershell,但之后我无法再导入我的模块(在很长一段时间内工作正常)。这是我收到的错误:

Import-Module : Method 'get_DataCollectionWarning' in type 'Microsoft.Azure.Commands.Automation.Cmdlet.GetAzureAutomationCertificate' from assembly 'Microsoft.Azure.Commands.Automation, Version=4.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation. At line:1 char:1 + im .\MyResources.psd1 + ~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Import-Module], TypeLoadException + FullyQualifiedErrorId : System.TypeLoadException,Microsoft.PowerShell.Commands.ImportModuleCommand

谁能告诉我这里可能出了什么问题。请注意,未实现的方法似乎来自 Azure PS 包。

如果您已将 Azure PowerShell 升级到版本 5.0.0,这是一个 重大变更版本,基于其 release notes.

您应该参阅 migration guide 以获得引入的重大更改的完整列表。

此外,Azure PowerShell 团队还发布了较新版本 5.0.1 修复了可能也与您的问题相关的问题。

Fixed assembly loading issue that caused some cmdlets to fail when executing in the following modules:

  • AzureRM.ApiManagement
  • AzureRM.Backup
  • AzureRM.Batch
  • AzureRM.Compute
  • AzureRM.DataFactories
  • AzureRM.HDInsight
  • AzureRM.KeyVault
  • AzureRM.RecoveryServices
  • AzureRM.RecoveryServices.Backup
  • AzureRM.RecoveryServices.SiteRecovery
  • AzureRM.RedisCache
  • AzureRM.SiteRecovery
  • AzureRM.Sql
  • AzureRM.Storage
  • AzureRM.StreamAnalytics

希望这对您有所帮助。