Skip to content

Disable-AzContextAutosave cmdlet skips logging of warnings subsequently #11492

@mahakjain314

Description

@mahakjain314

Description

This issue is specific to PowerShell scripts running in Azure Automation. Azure Automation run PowerShell/PowerShell Workflow scripts at scale for customers.

Recently, we have observed issues while running PowerShell automation job which uses Disable-AzContextAutosave cmdlet.

After { Disable-AzContextAutosave -Scope Process } cmdlet, logging of warnings in subsequent cmdlets are skipped.

Steps to reproduce

Running the below PS cmdlets in automation PowerShell runbook. QuickStart on how to create and run an Automation runbook.

Write-Warning "Before Disable-AzContextAutosave"
$null = Disable-AzContextAutosave -Scope Process
Write-Warning "After Disable-AzContextAutosave"

Output of the script

WARNING: Before Disable-AzContextAutosave

Note that the later Warning is not getting logged.

Environment data

Name                           Value                                                                                    
----                           -----                                                                                    
PSVersion                      5.1.15063.726                                                                            
PSEdition                      Desktop                                                                                  
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                  
BuildVersion                   10.0.15063.726                                                                           
CLRVersion                     4.0.30319.42000                                                                          
WSManStackVersion              3.0                                                                                      
PSRemotingProtocolVersion      2.3                                                                                      
SerializationVersion           1.1.0.1                                                                                  

Module versions

    Directory: C:\Modules\User
ModuleType Version    Name                                ExportedCommands                                              
---------- -------    ----                                ----------------                                              
Script     1.7.4      Az.Accounts                         {Disable-AzDataCollection, Disable-AzContextAutosave, Enabl...

Script     3.5.0      Az.Compute                          {Remove-AzAvailabilitySet, Get-AzAvailabilitySet, New-AzAva...

Script     1.12.0     Az.Resources                        {Get-AzProviderOperation, Remove-AzRoleAssignment, Get-AzRo...

Script     1.13.0     Az.Storage                          {Get-AzStorageAccount, Get-AzStorageAccountKey, New-AzStora...

Script     21.1.18218 SqlServer                           {Add-RoleMember, Add-SqlAvailabilityDatabase, Add-SqlAvaila...

    Directory: C:\Modules\Global


ModuleType Version    Name                                ExportedCommands                                              
---------- -------    ----                                ----------------                                              
Manifest   1.1.0.0    AuditPolicyDsc                                                                                    

Debug output

Set $DebugPreference='Continue' did not log any extra stream in Automation Output.

Few findings while investigating the issue –

  1. Only warning streams are skipped – writing errors are output work as expected.
  2. If AzureRm.Profile module is used instead of Az.Accounts, Disable-AzureRmContextAutosave does not skip the warnings. It works as expected.
  3. $warningpreference parameter is not modified after running the {Disable-AzContextAutosave -Scope Process } cmdlet. It is set to ‘Continue’.

Automation service do not have any special logic for modifying and controlling flow of any kind of output streams whether it is verbose, error or warning. Also since, everything works fine with AzureRm.Profile module in automation – we were wondering whether { Disable-AzContextAutosave -Scope Process } cmdlet from Az.Accounts module does something which could interfere with warning logs under any special circumstances.

Error output

Not Applicable.

Metadata

Metadata

Assignees

Labels

Azure PS TeamP0bugThis issue requires a change to an existing behavior in the product in order to be resolved.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions