AzurePowerShell@5 无法与 Az.Resources 6.16.0 配合使用

问题描述 投票:0回答:1

我有一个使用 AzurePowerShell@5 任务的 Azure DevOps 管道。我将服务连接传递给任务,然后它登录到 Azure。那部分很好。

任务执行的 PowerShell 代码调用 Get-AzADServicePrincipalAppRollAssignment,这需要最新的 Az.Resources 6.16.0。 Az.Resources 6.16.0 又需要 Az.Accounts 2.16.0。但是,AzurePowerShell@5 任务安装了 Az.Accounts 2.15.1。

当我尝试删除 Az.Accounts 2.15.1 并安装最新版本时,出现以下错误。不知道如何解决这个问题。程序集是否因为用于登录 Azure 而被锁定?

我已经阅读过有关使用 PowerShell 会话加载模块的内容,但我的预感是这会让我退出 Azure?

azure powershell ado
1个回答
0
投票

我同意@Galna Greta,

AzurePowershell@5
任务将仅使用代理上安装的Az版本。

我尝试安装

Az.Accounts - 2.16.0
Az.Resources
在 Azure Powershell 任务中使用 Install-Module 命令但失败了。因此,我没有使用
AzurePowershell@5
任务,而是使用了 Powershell@2 任务,如下所示:-

trigger:
- main

pool:
  vmImage: windows-latest

steps:
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      # Check if Az.Accounts module is installed, if not, install it
      if (-not (Get-Module -Name Az.Accounts -ListAvailable)) {
          Install-Module -Name Az.Accounts -Force -AllowClobber -Scope CurrentUser -Repository PSGallery -RequiredVersion 2.16.0
      } else {
          Update-Module -Name Az.Accounts -Force -AllowClobber -RequiredVersion 2.16.0
      }
      
      
      if (-not (Get-Module -Name Az.Resources -ListAvailable)) {
          Install-Module -Name Az.Resources -Force -AllowClobber -Scope CurrentUser -Repository PSGallery -RequiredVersion 6.16.0
      } else {
          
          $azAccountsVersion = (Get-InstalledModule -Name Az.Accounts).Version
          
          Install-Module -Name Az.Resources -Force -AllowClobber -Scope CurrentUser -Repository PSGallery -RequiredVersion $azAccountsVersion -AllowPrerelease
      }
      
      
      Get-InstalledModule -Name Az.Accounts, Az.Resources | Select-Object Name, Version
      
      $SecurePassword = ConvertTo-SecureString -String "q-xxxxxxxx_rsVKJKbRs" -AsPlainText -Force
      $TenantId = '83xxxxxx8592395'
      $ApplicationId = 'cxxxxxxxxxxxxxxb'
      $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $ApplicationId, $SecurePassword
      Connect-AzAccount -ServicePrincipal -TenantId $TenantId -Credential $Credential
      Get-AzADServicePrincipalAppRoleAssignment -ServicePrincipalId c0xxxxxxxxxx35cb

输出:-

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.