我在今天之前就配置了这条管道并使其工作。但是,根据最近对模块的更新,我现在收到此错误
Write-Error: This module requires Az.Accounts version 2.19.0. An earlier version of
Az.Accounts is imported in the current PowerShell session. Please open a new
session before importing this module. This error could indicate that multiple
incompatible versions of the Azure PowerShell cmdlets are installed on your
system. Please see https://aka.ms/azps-version-error for troubleshooting
information.
我尝试将其添加到我的模块脚本中以删除现有的并安装新版本 2.19.0。但没有运气
$desiredVersion = "2.19.0"
$installedModule = Get-InstalledModule -Name "Az.Accounts" -ErrorAction SilentlyContinue
Write-Output "$($installedModule)"
if ($installedModule) {
if ($installedModule.Version.ToString() -ne $desiredVersion) {
Uninstall-Module -Name "Az.Accounts" -Force -ErrorAction SilentlyContinue
Install-Module -Name "Az.Accounts" -RequiredVersion $desiredVersion -Force -AllowClobber -Scope CurrentUser -Repository PSGallery
}
} else {
Install-Module -Name "Az.Accounts" -RequiredVersion $desiredVersion -Force -AllowClobber -Scope CurrentUser -Repository PSGallery
}
Import-Module Az.Accounts
您可以尝试在 Azure PowerShell 任务之前添加 PowerShell 任务来安装模块
Az.Accounts 2.19.0
。请参阅下面的示例作为参考。
stages:
- stage: A
jobs:
- job: A1
pool:
vmImage: ubuntu-latest
steps:
- task: PowerShell@2
displayName: 'Install Module Az.Accounts'
inputs:
pwsh: true
targetType: 'inline'
script: 'Install-Module -Name Az.Accounts -RequiredVersion 2.19.0 -Repository PSGallery -Force'
- task: AzurePowerShell@5
displayName: 'Check Module Az.Accounts'
inputs:
pwsh: true
azureSubscription: 'myArmConnection'
ScriptType: 'InlineScript'
Inline: 'Get-InstalledModule -Name "Az.Accounts"'
azurePowerShellVersion: 'LatestVersion'