Skip to content

Connect-AzAccount -Identity -WhatIf doesn't output a notification from within an Azure runbook #28944

@DavidRawling

Description

@DavidRawling

Description

When using Connect-AzAccount within an Azure Automation PowerShell runbook, setting $WhatIfPreference to $true or providing -WhatIf:$true to Connect-AzAccount does not connect (expected) and does not produce output (unexpected).

The same command at an interactive PowerShell prompt, or from within a locally saved script produces the output shown here:

What if: Performing the operation "log in" on target "ManagedService account in environment 'AzureCloud'"

The expected behaviour is that the same command in the PowerShell runbook will also output the notification shown.

This appears to be related to #12511.

The documentation at https://learn.microsoft.com/en-us/powershell/module/az.accounts/connect-azaccount appears to state that in WhatIf mode, a message will be displayed:

-WhatIf
Shows what would happen if the cmdlet runs.

Issue script & Debug output

Code:
$DebugPreference='Continue'
Write-Output "----- Before call to Connect-AzAccount"
Connect-AzAccount -Identity -WhatIf
Write-Output "----- After call to Connect-AzAccount"
Resolve-AzError
Write-Output "----- After call to Resolve-AzError"

Output (note that no message is shown here for the output of Connect-AzAccount, despite being in WhatIf mode):

----- Before call to Connect-AzAccount
----- After call to Connect-AzAccount
----- After call to Resolve-AzError

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.6
PSEdition                      Core
GitCommitId                    7.4.6
OS                             Microsoft Windows 10.0.20348
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Module versions

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     5.3.1                 Az.Accounts                         {Add-AzEnvironment, Clear-AzConfig, Clear-AzContex

Error output

Resolve-AzError produces no output

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue requires a change to an existing behavior in the product in order to be resolved.customer-reportedneeds-triageThis is a new issue that needs to be triaged to the appropriate team.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions