Skip to content

[enhancement]: Reuse Azure PowerShell session and/or modules #21944

@gabbsmo

Description

@gabbsmo

Task name

AzurePowerShell

Describe your feature request here

When running separate AzurePowerShell tasks, I can see in the debug log that it Clear-AzContext and reauthenticates with Connect-AzAccount.

2026-03-27T08:22:36.8268513Z ##[command]Import-Module -Name /usr/share/az_14.6.0/Az.Accounts/5.3.3/Az.Accounts.psd1 -Global
2026-03-27T08:22:37.9737404Z ##[command]Clear-AzContext -Scope Process
2026-03-27T08:22:38.1952583Z ##[command]Clear-AzContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue
2026-03-27T08:22:38.2594744Z ##[command] Connect-AzAccount -ServicePrincipal -Tenant 67a9601a-bcae-4b5d-bc95-d5eb01f91274 -ApplicationId *** -FederatedToken ***** -Environment AzureCloud -Scope Process
2026-03-27T08:22:39.4480495Z ##[command] Set-AzContext -SubscriptionId 944ab1af-d7e9-49fc-b698-26003bcd10f0 -TenantId 67a9601a-bcae-4b5d-bc95-d5eb01f91274

With debug logging enabled I can also see that modules are imported, even if they where imported in a previous step.

# lots of these
2026-03-27T08:33:17.2407731Z ‌VERBOSE: Importing cmdlet Register-AzModule.‌

Can either session or modules be cached between tasks?

Unfortunately my requirements does not allow me to run everything in a single task as there are other tasks needed inbetween.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions