Azure / Azure/azure-powershell

Import-Module Az.Accounts fails with "Access to the path 'Global\AzurePowerShellConfigInit' is denied" when used concurrent

Open
#26,907 7 comments 6 reactions 0 assignees View on GitHub
bug customer-reported needs-team-attention
Dominant language
C#
Stars
4.8k
Forks
4.3k
Avg merge
2d 17h
Merged PRs (30d)
51

Description

### Description

This is how to ‘build’ an environment to reproduce the issue on a windows computer:
1. Create 4 local accounts with no additional permissions
2. Create a folder for powershell scripts
3. Create a powershell script called test-azaccounts.ps1 with the following content:
`. "$PSScriptRoot\test-azaccounts2.ps1" *>> "$home\Documents\test-azaccounts.log"`

4. Create a powershell script called test-azaccounts2.ps1 with the following content:
```
$ErrorActionPreference = 'Stop'
$InformationPreference = 'Continue'
$DebugPreference = 'Continue'

Write-Information "$(Get-Date) Start"

try {
$null = Import-Module Az.Accounts
}
catch {
Write-Information "$(Get-Date) Error: $($_.Exception.Message)"
}
Write-Information "$(Get-Date) End"

```
5. Create a scheduled task for each local account (running as the local account) with the same trigger/schedule running script test-azaccount.ps1 (run powershell.exe with arguments: -noninteractive -file \test-azaccounts.ps1)
The script will create a logfile in the document folder of each local account.
You will notice that only 1 scheduled task will succeed, the other 3 will fail.

### Issue script & Debug output

```PowerShell
See description
```

### Environment data

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

### Module versions

```PowerShell
On 1 of the instances:
Script 3.0.3 Az.Accounts {Add-AzEnvironment, Clear-AzConfig, Clear-AzConte…

On the other instances:
```

### Error output

```PowerShell
On 1 of the instances the following is logged:

12/19/2024 13:30:02 Start
Initializing ConditionalAssemblyContext. PSEdition is [Core]. PSVersion is [7.4.6].
Initializing ConditionalAssemblyProvider. AssemblyRootPath is [C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\3.0.3\StartupScripts\..\lib].
Registering Az shared AssemblyLoadContext.
AssemblyLoadContext registered.
12/19/2024 13:30:04 End

On the other instances:
12/19/2024 13:30:02 Start
Initializing ConditionalAssemblyContext. PSEdition is [Core]. PSVersion is [7.4.6].
Initializing ConditionalAssemblyProvider. AssemblyRootPath is [C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\3.0.3\StartupScripts\..\lib].
Registering Az shared AssemblyLoadContext.
AssemblyLoadContext registered.
12/19/2024 13:30:04 Error: Access to the path 'Global\AzurePowerShellConfigInit' is denied.
12/19/2024 13:30:04 End
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.