-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Description
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-AzErrorEnvironment 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.0Module 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