J Nguyen
J Nguyen

Reputation: 147

Azure Pipeline: Run Azure command in PowerShell script got "Insufficient privileges to complete the operation", even run as the service connection

I tried to run a powershell script as Service Connection. Given that all the parameters are correct, no powershell script syntax error. The Service connection is also the valid one as I normally use it successfully for other AzureCLI task. I am sure My Service connection can access to all the pipelines. there is no restriction to it that I am aware of.

- task: AzurePowerShell@5
  displayName: 'Run my script'
  inputs:
    azureSubscription: 'My Service Connection'
    ScriptPath: '$(Agent.BuildDirectory)/drop/MyPowerShellScript.ps1'
    ScriptArguments: >
      -ADGroupName '${{ parameters.domainTeamName }}'
    FailOnStandardError: true
    azurePowerShellVersion: OtherVersion
    preferredAzurePowerShellVersion: 6.5.0
    pwsh: true

and I got this error message when I run the pipeline enter image description here

Here is the script code, the last line is where it failed. It cannot run that azure command "Get AzADGroup" because it does not have permission.

[CmdletBinding()]
param (
    [ValidateNotNullOrEmpty()][Parameter(Mandatory = $true)][string]$ADGroupName
)

Set-StrictMode -Version 3

$ADGroup = Get-AzADGroup -DisplayName $ADGroupName

I feel weird because I have run the task as the valid "My Service Connection". it should have had permission to do everything. Anyone can help me please. Thanks

Upvotes: 0

Views: 346

Answers (0)

Related Questions