Open NikolaiKleppe opened 5 months ago
Hi, managed to suppress the output by redirecting the stream like this instead of piping to Out-Null:
$con = Connect-AzAccount -ServicePrincipal -TenantId $tenantId -Credential $credential -Subscription $subscriptionId -WarningAction Ignore *>&1 | Write-Verbose
*> $null
also works
Thanks for finding a workaround @NikolaiKleppe. Given you've closed this issue, I may open a new one referencing this, as there should surely be a way to disable such notices (without having to use an undocumented stream redirection). If I remember correctly the AzureRm modules did things like this, but there was a documented way to prevent it with an environment variable switch.
Hi @robinmalik, indeed I might have closed this issue a bit prematurely. There should definitely be a native way to disable these messages, especially when using Service Principal Authentication.
I suppose I can re-open this issue as well
Thanks for reporting @NikolaiKleppe . Just to clarify a little bit, by "requires that anything sent to the output stream must be JSON" do you mean (a) you don't rely on any output of Azure PowerShell at all or (b) you convert the output of Azure PowerShell to JSON format then consume it?
cc @BethanyZhou
Hi @NikolaiKleppe , a simple way to disable the announcement message is ignoring the information message by Connect-AzAccount -InformationAction Ignore
.
What about adding a Update-AzConfig
setting to disable announcements?
@BethanyZhou: Unless $InformationPreferences = 'Continue'
or -InformationAction 'Continue'
cmdlets should not output it?
Thanks for reporting @NikolaiKleppe . Just to clarify a little bit, by "requires that anything sent to the output stream must be JSON" do you mean (a) you don't rely on any output of Azure PowerShell at all or (b) you convert the output of Azure PowerShell to JSON format then consume it?
cc @BethanyZhou
Hi @isra-fel , option (b) - The desired output is converted to JSON then consumed.
The last line of the script is basically $Object | ConvertTo-Json
and that's the only thing that should be in stdout
.
Hi @NikolaiKleppe , a simple way to disable the announcement message is ignoring the information message by
Connect-AzAccount -InformationAction Ignore
.
Thanks @BethanyZhou , this works as well and is better than redirecting the output stream
Next challenge / logical flaw: Hide announcement and use -UseDeviceAuthentication
.
Please do not set InformationAction or $InformationPreference to Ignore if you want to use device code authentication.
Description
We are using some PowerShell scripts with the Terraform External provider, which requires that anything sent to the output stream must be JSON
This new announcement (and the "Retrieving subscriptions for the selection" text) is captured and crashes the pipeline and I haven't figured out how to disable it.
Authentication is by Service Principal so this shouldn't be relevant anyway, but I've disabled the LoginExperienceV2 just in case and that doesn't do anything either.
Not sure if this issue should be for Azure PowerShell or the Terraform team.
Example:
Then in our pipeline agent I see this is captured:
Notice the reference to the R character from the pipeline output, which is from "Retrieving.."
Issue script & Debug output
Environment data
Module versions
Error output
No response