azurevisual-studio-codeazure-powershell

Unable to acquire token for tenant 'organizations' with error 'InteractiveBrowserCredential authentication failed: User canceled authentication. '


Connect-AzAccount -Tenant 'xxxxx' -SubscriptionId 'xxxx'

# Get the Resource Group Name
$resourceGroupName = "city-app-rg-xx-uat"

# Get all Private Endpoints in the Resource Group
$privateEndpoints = Get-AzPrivateEndpoint -ResourceGroupName $resourceGroupName

# Create a list to store the data
$data = @()

# Loop through each Private Endpoint
foreach ($privateEndpoint in $privateEndpoints) {
    $fqdn = $privateEndpoint.PrivateDnsZoneGroup.Name
    $ipAddresses = $privateEndpoint.PrivateIPAddresses -join ","
    $name = $privateEndpoint.Name

    $data += [PSCustomObject]@{
        FQDN = $fqdn
        IPAddress = $ipAddresses
        Name = $name
    }
}

# Export the data to a CSV file
$data | Export-Csv -Path "PrivateEndpointDetails.csv" -NoTypeInformation

When I try to execute the above script in VS Code, I'm getting the below error:

PS C:\Users\User5574\source\repos\Automations> .\GetPrvEPsData.ps1
Please select the account you want to login with.

Connect-AzAccount: C:\Users\User5574\source\repos\Automations\GetPrvEPsData.ps1:1:1
Line |
   1 |  Connect-AzAccount -Tenant 'xxxxx' -Sub …
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | InteractiveBrowserCredential authentication failed: User canceled authentication.  Could not find tenant id for provided tenant domain
     | 'xxxxx'. Please ensure that the provided user is found in the provided tenant domain.
Get-AzPrivateEndpoint: C:\Users\User5574\source\repos\Automations\GetPrvEPsData.ps1:7:21
Line |
   7 |  … Endpoints = Get-AzPrivateEndpoint -ResourceGroupName $resourceGroupNa …
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | No subscription found in the context.  Please ensure that the credentials you provided are authorized to access an Azure subscription, then run Connect-AzAccount to login.

I have tried the below steps:

  1. Running VS Code as administrator
  2. Logging to VS Code using Azure Sign in with the account that has access to the azure resources.
  3. Setting the execution policy to remotesigned
  4. Updating the Azure PowerShell modules in the Vs Code.

Still, I'm getting the above errors. How to fix..!


Solution

  • To resolve the error, try running below PowerShell command in your VS code Terminal:

    Update-AzConfig -EnableLoginByWam $false
    

    enter image description here

    I have below private endpoint in resource group named Sri :

    enter image description here

    When I ran PowerShell script now, it worked, and I got details successfully in csv file as below:

    Connect-AzAccount -Tenant 'tenantId' -SubscriptionId 'subId'
    
    # Get the Resource Group Name
    $resourceGroupName = "rgname"
    
    # Get all Private Endpoints in the Resource Group
    $privateEndpoints = Get-AzPrivateEndpoint -ResourceGroupName $resourceGroupName
    
    # Create a list to store the data
    $data = @()
    
    # Loop through each Private Endpoint
    foreach ($privateEndpoint in $privateEndpoints) {
        $fqdn = $privateEndpoint.PrivateDnsZoneGroup.Name
        $ipAddresses = $privateEndpoint.PrivateIPAddresses -join ","
        $name = $privateEndpoint.Name
    
        $data += [PSCustomObject]@{
            FQDN = $fqdn
            IPAddress = $ipAddresses
            Name = $name
        }
    }
    
    # Export the data to a CSV file
    $data | Export-Csv -Path "PrivateEndpointDetails.csv" -NoTypeInformation
    

    Response:

    enter image description here