Import-Module Az.Accounts fails with "Access to the path 'Global\AzurePowerShellConfigInit' is denied" when used concurrent
Description
This is how to ‘build’ an environment to reproduce the issue on a windows computer:
-
Create 4 local accounts with no additional permissions
-
Create a folder for powershell scripts
-
Create a powershell script called test-azaccounts.ps1 with the following content:
. "$PSScriptRoot\test-azaccounts2.ps1" *>> "$home\Documents\test-azaccounts.log" -
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"
- 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
See description
Environment data
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
On 1 of the instances:
Script 3.0.3 Az.Accounts {Add-AzEnvironment, Clear-AzConfig, Clear-AzConte…
On the other instances:
Error output
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
This looks very similar to this issue I reported: https://github.com/microsoft/azure-pipelines-tasks/issues/20245
It seems caused by mutex created by one user can't be accessed by other users. Can the script be modified to run with one single user?
It seems caused by mutex created by one user can't be accessed by other users. Can the script be modified to run with one single user?
It also happens when all processes are run by the same user.
Then I assume it's a different problem with a different root cause. See https://github.com/Azure/azure-powershell/issues/25778
We need more information about this issue to help address it.
What other information do you need? The opening post contains instructions to reproduce this issue.
It seems caused by mutex created by one user can't be accessed by other users. Can the script be modified to run with one single user?
No, the use case is running scripts concurrently with different users on the same machine,
Can confirm I just received the same error described in a live scenario. Note the following:
- Using v. 4.1.0 of Az.Accounts module
- PowerShell v. 7.5.3
- It happens intermittently between two scheduled tasks that (apparently) start at the same time (ran by different users, same machine)
Was able to extract the following verbose logging: `VERBOSE: Loading module from path 'C:\Program Files\PowerShell\Modules\Az.Accounts\4.1.0\Az.Accounts.psd1'. VERBOSE: Loading 'Assembly' from path 'C:\Program Files\PowerShell\Modules\Az.Accounts\4.1.0\Microsoft.Azure.PowerShell.AssemblyLoading.dll'. VERBOSE: Loading 'Assembly' from path 'C:\Program Files\PowerShell\Modules\Az.Accounts\4.1.0\Microsoft.Azure.PowerShell.Authentication.Abstractions.dll'. VERBOSE: Loading 'Assembly' from path 'C:\Program Files\PowerShell\Modules\Az.Accounts\4.1.0\Microsoft.Azure.PowerShell.Authentication.dll'. VERBOSE: Loading 'Assembly' from path 'C:\Program Files\PowerShell\Modules\Az.Accounts\4.1.0\Microsoft.Azure.PowerShell.Authenticators.dll'. VERBOSE: Loading 'Assembly' from path 'C:\Program Files\PowerShell\Modules\Az.Accounts\4.1.0\Microsoft.Azure.PowerShell.Authentication.ResourceManager.dll'. VERBOSE: Loading 'Assembly' from path 'C:\Program Files\PowerShell\Modules\Az.Accounts\4.1.0\Microsoft.Azure.PowerShell.Clients.Authorization.dll'. VERBOSE: Loading 'Assembly' from path 'C:\Program Files\PowerShell\Modules\Az.Accounts\4.1.0\Microsoft.Azure.PowerShell.Clients.Compute.dll'. VERBOSE: Loading 'Assembly' from path 'C:\Program Files\PowerShell\Modules\Az.Accounts\4.1.0\Microsoft.Azure.PowerShell.Clients.Graph.Rbac.dll'. VERBOSE: Loading 'Assembly' from path 'C:\Program Files\PowerShell\Modules\Az.Accounts\4.1.0\Microsoft.Azure.PowerShell.Clients.Monitor.dll'. VERBOSE: Loading 'Assembly' from path 'C:\Program Files\PowerShell\Modules\Az.Accounts\4.1.0\Microsoft.Azure.PowerShell.Clients.Network.dll'. VERBOSE: Loading 'Assembly' from path 'C:\Program Files\PowerShell\Modules\Az.Accounts\4.1.0\Microsoft.Azure.PowerShell.Clients.PolicyInsights.dll'. VERBOSE: Loading 'Assembly' from path 'C:\Program Files\PowerShell\Modules\Az.Accounts\4.1.0\Microsoft.Azure.PowerShell.Clients.ResourceManager.dll'. VERBOSE: Loading 'Assembly' from path 'C:\Program Files\PowerShell\Modules\Az.Accounts\4.1.0\Microsoft.Azure.PowerShell.Common.dll'. VERBOSE: Loading 'Assembly' from path 'C:\Program Files\PowerShell\Modules\Az.Accounts\4.1.0\Microsoft.Azure.PowerShell.Storage.dll'. VERBOSE: Loading 'Assembly' from path 'C:\Program Files\PowerShell\Modules\Az.Accounts\4.1.0\Microsoft.Azure.PowerShell.Clients.Storage.Management.dll'. VERBOSE: Loading 'Assembly' from path 'C:\Program Files\PowerShell\Modules\Az.Accounts\4.1.0\Microsoft.Azure.PowerShell.Clients.KeyVault.dll'. VERBOSE: Loading 'Assembly' from path 'C:\Program Files\PowerShell\Modules\Az.Accounts\4.1.0\Microsoft.Azure.PowerShell.Clients.Websites.dll'. VERBOSE: Loading 'Assembly' from path 'C:\Program Files\PowerShell\Modules\Az.Accounts\4.1.0\Hyak.Common.dll'. VERBOSE: Loading 'Assembly' from path 'C:\Program Files\PowerShell\Modules\Az.Accounts\4.1.0\Microsoft.ApplicationInsights.dll'. VERBOSE: Loading 'Assembly' from path 'C:\Program Files\PowerShell\Modules\Az.Accounts\4.1.0\Microsoft.Azure.Common.dll'. VERBOSE: Loading 'Assembly' from path 'C:\Program Files\PowerShell\Modules\Az.Accounts\4.1.0\Microsoft.Rest.ClientRuntime.dll'. VERBOSE: Loading 'Assembly' from path 'C:\Program Files\PowerShell\Modules\Az.Accounts\4.1.0\Microsoft.Rest.ClientRuntime.Azure.dll'. VERBOSE: Loading 'Assembly' from path 'C:\Program Files\PowerShell\Modules\Az.Accounts\4.1.0\Microsoft.WindowsAzure.Storage.dll'. VERBOSE: Loading 'Assembly' from path 'C:\Program Files\PowerShell\Modules\Az.Accounts\4.1.0\Microsoft.Azure.PowerShell.Clients.Aks.dll'. VERBOSE: Loading 'Assembly' from path 'C:\Program Files\PowerShell\Modules\Az.Accounts\4.1.0\Microsoft.Azure.PowerShell.Strategies.dll'. VERBOSE: Loading 'Assembly' from path 'C:\Program Files\PowerShell\Modules\Az.Accounts\4.1.0\Microsoft.Azure.PowerShell.Common.Share.dll'. VERBOSE: Loading 'Assembly' from path 'C:\Program Files\PowerShell\Modules\Az.Accounts\4.1.0\FuzzySharp.dll'. VERBOSE: Loading 'FormatsToProcess' from path 'C:\Program Files\PowerShell\Modules\Az.Accounts\4.1.0\Accounts.format.ps1xml'. VERBOSE: Loading 'FormatsToProcess' from path 'C:\Program Files\PowerShell\Modules\Az.Accounts\4.1.0\Accounts.generated.format.ps1xml'. VERBOSE: Populating RepositorySourceLocation property for module Az.Accounts. VERBOSE: Loading module from path 'C:\Program Files\PowerShell\Modules\Az.Accounts\4.1.0\Az.Accounts.psm1'. VERBOSE: Loading module from path 'C:\Program Files\PowerShell\Modules\Az.Accounts\4.1.0\Microsoft.Azure.PowerShell.Cmdlets.Accounts.dll'.
TerminatingError(Import-Module): "Access to the path 'Global\AzurePowerShellConfigInit' is denied." Import-Module: Access to the path 'Global\AzurePowerShellConfigInit' is denied.`
Found this issue post while looking up the error. Going to fix the scheduling so it's staggered, but thought this might be worth noting.