Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.26k stars 3.86k forks source link

Az.Accounts module cannot be imported: Could not load type 'Microsoft.Identity.Client.Extensions.Msal.Storage' from assembly 'Microsoft.Identity.Client.Extensions.Msal #20685

Closed Obenscripe closed 1 year ago

Obenscripe commented 1 year ago

Description

This is module version 2.11.1 (which is the hotfix for 2.10.4.) Either I am missing something or this hotfix is not fully working on my environment. PS 5.1, server 2016 running in an elevated ISE window.

Why does the "resolve-azerror" say "Not Installed?" I just un-installed then re installed the latest version 2.11.1 hotfix so this is a bit odd. is this because the module cannot be imported?

Issue script & Debug output

PS C:\Windows\system32> import-module Az.Accounts -debug
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Az.Accounts.psd1'.
VERBOSE: Cannot verify the Microsoft .NET Framework version 4.7.2 because it is not included in the list of permitted versions.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.AssemblyLoading.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.AssemblyLoading.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Authentication.Abstractions.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Authentication.Abstractions.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Authentication.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Authentication.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Authenticators.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Authenticators.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Authentication.ResourceManager.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Authentication.ResourceManager.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Clients.Authorization.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Clients.Authorization.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Clients.Compute.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Clients.Compute.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Clients.Graph.Rbac.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Clients.Graph.Rbac.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Clients.Monitor.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Clients.Monitor.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Clients.Network.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Clients.Network.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Clients.PolicyInsights.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Clients.PolicyInsights.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Clients.ResourceManager.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Clients.ResourceManager.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Common.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Common.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Storage.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Storage.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Clients.Storage.Management.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Clients.Storage.Management.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Clients.KeyVault.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Clients.KeyVault.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Clients.Websites.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Clients.Websites.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Hyak.Common.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Hyak.Common.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\PnP.PowerShell\1.11.0\Common\Microsoft.ApplicationInsights.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\PnP.PowerShell\1.11.0\Common\Microsoft.ApplicationInsights.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.Common.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.Common.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Rest.ClientRuntime.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Rest.ClientRuntime.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Rest.ClientRuntime.Azure.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Rest.ClientRuntime.Azure.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.WindowsAzure.Storage.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.WindowsAzure.Storage.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.WindowsAzure.Storage.DataMovement.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.WindowsAzure.Storage.DataMovement.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Clients.Aks.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Clients.Aks.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Strategies.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Strategies.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Common.Share.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Microsoft.Azure.PowerShell.Common.Share.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\FuzzySharp.dll'.
VERBOSE: Loading 'Assembly' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\FuzzySharp.dll'.
VERBOSE: Loading 'FormatsToProcess' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Accounts.format.ps1xml'.
VERBOSE: Loading 'FormatsToProcess' from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Accounts.generated.format.ps1xml'.
VERBOSE: Populating RepositorySourceLocation property for module Az.Accounts.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Az.Accounts.psm1'.
Import-Module : Could not load type 'Microsoft.Identity.Client.Extensions.Msal.Storage' from assembly 'Microsoft.Identity.Client.Extensions.Msal, Version=2.18.4.0, Culture=neutral, 
PublicKeyToken=0a613f4dd989e8ae'.
At C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.11.1\Az.Accounts.psm1:87 char:1
+ Import-Module (Join-Path -Path $PSScriptRoot -ChildPath Microsoft.Azu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Import-Module], TypeLoadException
    + FullyQualifiedErrorId : System.TypeLoadException,Microsoft.PowerShell.Commands.ImportModuleCommand

VERBOSE: Exporting function 'Test-DotNet'.
VERBOSE: Exporting function 'Preload-Assembly'.
VERBOSE: Exporting function 'Write-InstallationCheckToFile'.

PS C:\Windows\system32>

Environment data

PS C:\Windows\system32> $PSVersionTable

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

Module versions

PS C:\Windows\system32> get-module Az*

ModuleType Version    Name                                ExportedCommands                                                                                                                 
---------- -------    ----                                ----------------                                                                                                                 
Script     2.11.1     Az.Accounts                                                                                                                                                          
Script     3.2.0      Az.OperationalInsights              {Disable-AzOperationalInsightsIISLogCollection, Disable-AzOperationalInsightsLinuxCustomLogCollection, Disable-AzOperationalIn...

PS C:\Windows\system32> get-installedmodule "az*"

Version              Name                                Repository           Description                                                                                                  
-------              ----                                ----------           -----------                                                                                                  
9.2.0                Az                                  PSGallery            Microsoft Azure PowerShell - Cmdlets to manage resources in Azure. This module is compatible with PowerShe...
2.11.1               Az.Accounts                         PSGallery            Microsoft Azure PowerShell - Accounts credential management cmdlets for Azure Resource Manager in Windows ...
2.0.0                Az.Advisor                          PSGallery            Microsoft Azure PowerShell: Advisor cmdlets                                                                  
5.1.0                Az.Aks                              PSGallery            Microsoft Azure PowerShell - Azure managed Kubernetes cmdlets for Windows PowerShell and PowerShell Core.... 
1.1.4                Az.AnalysisServices                 PSGallery            Microsoft Azure PowerShell - Analysis Services cmdlets for Windows PowerShell and PowerShell Core....        
4.0.1                Az.ApiManagement                    PSGallery            Microsoft Azure PowerShell - Api Management service cmdlets for Azure Resource Manager in Windows PowerShe...
1.2.0                Az.AppConfiguration                 PSGallery            Microsoft Azure PowerShell: AppConfiguration cmdlets                                                         
2.2.0                Az.ApplicationInsights              PSGallery            Microsoft Azure PowerShell: ApplicationInsights cmdlets                                                      
2.0.0                Az.Attestation                      PSGallery            Microsoft Azure PowerShell - Attestation service cmdlets for Azure Resource Manager in Windows PowerShell ...
1.8.0                Az.Automation                       PSGallery            Microsoft Azure PowerShell - Automation service cmdlets for Azure Resource Manager in Windows PowerShell a...
3.2.1                Az.Batch                            PSGallery            Microsoft Azure PowerShell - Batch service cmdlets for Azure Resource Manager in Windows PowerShell and Po...
2.0.0                Az.Billing                          PSGallery            Microsoft Azure PowerShell - Billing service cmdlets for Azure Resource Manager in Windows PowerShell and ...
2.1.0                Az.Cdn                              PSGallery            Microsoft Azure PowerShell: Cdn cmdlets                                                                      
1.1.0                Az.CloudService                     PSGallery            Microsoft Azure PowerShell: CloudService cmdlets                                                             
1.12.0               Az.CognitiveServices                PSGallery            Microsoft Azure PowerShell - Cognitive Services management cmdlets for Azure Resource Manager in Windows P...
5.2.0                Az.Compute                          PSGallery            Microsoft Azure PowerShell - Compute service cmdlets for Azure Resource Manager in Windows PowerShell and ...
1.0.0                Az.ConfidentialLedger               PSGallery            Microsoft Azure PowerShell: ConfidentialLedger cmdlets                                                       
3.1.0                Az.ContainerInstance                PSGallery            Microsoft Azure PowerShell: ContainerInstance cmdlets                                                        
3.0.0                Az.ContainerRegistry                PSGallery            Microsoft Azure PowerShell - Container Registry service cmdlets for Azure Resource Manager in Windows Powe...
1.9.0                Az.CosmosDB                         PSGallery            Microsoft Azure PowerShell - CosmosDB service cmdlets for Azure Resource Manager in Windows PowerShell and...
1.1.0                Az.DataBoxEdge                      PSGallery            Microsoft Azure PowerShell - DataBoxEdge service cmdlets for Azure Resource Manager in Windows PowerShell ...
1.4.0                Az.Databricks                       PSGallery            Microsoft Azure PowerShell: Databricks cmdlets                                                               
1.16.11              Az.DataFactory                      PSGallery            Microsoft Azure PowerShell - Data Factory service cmdlets for Azure Resource Manager in Windows PowerShell...
1.0.2                Az.DataLakeAnalytics                PSGallery            Microsoft Azure PowerShell - Data Lake Analytics in Windows PowerShell and PowerShell Core....               
1.3.0                Az.DataLakeStore                    PSGallery            Microsoft Azure PowerShell - Azure Data Lake Store cmdlets in Windows PowerShell and PowerShell Core....     
1.0.1                Az.DataProtection                   PSGallery            Microsoft Azure PowerShell: DataProtection cmdlets                                                           
1.0.1                Az.DataShare                        PSGallery            Microsoft Azure PowerShell - DataShare service cmdlets for Azure Resource Manager in Windows PowerShell an...
1.1.0                Az.DeploymentManager                PSGallery            PowerShell .Net Core Microsoft Azure PowerShell - Deployment Manager cmdlets for Azure Resource Manager....  
3.1.1                Az.DesktopVirtualization            PSGallery            Microsoft Azure PowerShell: DesktopVirtualization cmdlets                                                    
1.0.2                Az.DevTestLabs                      PSGallery            Microsoft Azure PowerShell - DevTest Labs service cmdlets for Azure Resource Manager in Windows PowerShell...
1.1.2                Az.Dns                              PSGallery            Microsoft Azure PowerShell - DNS service cmdlets for Azure Resource Manager in Windows PowerShell and Powe...
1.5.0                Az.EventGrid                        PSGallery            Microsoft Azure PowerShell - Event Grid service cmdlets for Azure Resource Manager in Windows PowerShell a...
3.2.0                Az.EventHub                         PSGallery            Microsoft Azure PowerShell - Event Hubs service cmdlets for Azure Resource Manager in Windows PowerShell a...
1.9.0                Az.FrontDoor                        PSGallery            Microsoft Azure PowerShell - Front Door service cmdlets for Azure Resource Manager in Windows PowerShell a...
4.0.6                Az.Functions                        PSGallery            Microsoft Azure PowerShell - Azure Functions service cmdlets for Azure Resource Manager in Windows PowerSh...
5.0.1                Az.HDInsight                        PSGallery            Microsoft Azure PowerShell - HDInsight service cmdlets for Azure Resource Manager in Windows PowerShell an...
2.0.0                Az.HealthcareApis                   PSGallery            Microsoft Azure PowerShell: HealthcareApis cmdlets                                                           
2.7.4                Az.IotHub                           PSGallery            Microsoft Azure PowerShell - IoT Hub service cmdlets for Azure Resource Manager in Windows PowerShell and ...
4.9.1                Az.KeyVault                         PSGallery            Microsoft Azure PowerShell - Key Vault service cmdlets for Azure Resource Manager in Windows PowerShell an...
2.1.0                Az.Kusto                            PSGallery            Microsoft Azure PowerShell: Kusto cmdlets                                                                    
1.5.0                Az.LogicApp                         PSGallery            Microsoft Azure PowerShell - Logic Apps cmdlets for Azure Resource Manager in Windows PowerShell and Power...
1.1.3                Az.MachineLearning                  PSGallery            Microsoft Azure PowerShell - Machine Learning Web Services cmdlets for Azure Resource Manager in Windows P...
1.2.1                Az.Maintenance                      PSGallery            Microsoft Azure PowerShell - Maintenance cmdlets for Azure Resource Manager in Windows PowerShell and Powe...
1.1.0                Az.ManagedServiceIdentity           PSGallery            Microsoft Azure PowerShell: ManagedServiceIdentity cmdlets                                                   
3.0.0                Az.ManagedServices                  PSGallery            Microsoft Azure PowerShell: ManagedServices cmdlets                                                          
2.0.0                Az.MarketplaceOrdering              PSGallery            Microsoft Azure PowerShell: MarketplaceOrdering cmdlets                                                      
1.1.1                Az.Media                            PSGallery            Microsoft Azure PowerShell - Media service cmdlets for Azure Resource Manager in Windows PowerShell and Po...
2.1.0                Az.Migrate                          PSGallery            Microsoft Azure PowerShell: Migrate cmdlets                                                                  
4.3.0                Az.Monitor                          PSGallery            Microsoft Azure PowerShell - Monitor service cmdlets for Azure Resource Manager in Windows PowerShell and ...
1.1.0                Az.MySql                            PSGallery            Microsoft Azure PowerShell: MySql cmdlets                                                                    
5.2.0                Az.Network                          PSGallery            Microsoft Azure PowerShell - Networking service cmdlets for Azure Resource Manager in Windows PowerShell a...
1.1.1                Az.NotificationHubs                 PSGallery            Microsoft Azure PowerShell - Notification Hubs cmdlets for Azure Resource Manager in Windows PowerShell an...
3.2.0                Az.OperationalInsights              PSGallery            Microsoft Azure PowerShell - Operational Insights service cmdlets for Azure Resource Manager in Windows Po...
1.5.1                Az.PolicyInsights                   PSGallery            Microsoft Azure PowerShell - Azure Policy Insights cmdlets for Windows PowerShell and PowerShell Core. All...
1.1.0                Az.PostgreSql                       PSGallery            Microsoft Azure PowerShell: PostgreSql cmdlets                                                               
1.2.0                Az.PowerBIEmbedded                  PSGallery            Microsoft Azure PowerShell - Power BI Embedded service management cmdlets for Azure Resource Manager in Wi...
1.0.3                Az.PrivateDns                       PSGallery            Microsoft Azure PowerShell - Private DNS service cmdlets for Azure Resource Manager in Windows PowerShell ...
6.1.2                Az.RecoveryServices                 PSGallery            Microsoft Azure PowerShell - Recovery Services cmdlets for Azure Resource Manager in Windows PowerShell an...
1.6.0                Az.RedisCache                       PSGallery            Microsoft Azure PowerShell - Redis Cache service cmdlets for Azure Resource Manager in Windows PowerShell ...
1.1.0                Az.RedisEnterpriseCache             PSGallery            Microsoft Azure PowerShell: RedisEnterpriseCache cmdlets                                                     
1.0.3                Az.Relay                            PSGallery            Microsoft Azure PowerShell - Relay service cmdlets for Azure Resource Manager in Windows PowerShell and Po...
1.1.0                Az.ResourceMover                    PSGallery            Microsoft Azure PowerShell: ResourceMover cmdlets                                                            
6.5.1                Az.Resources                        PSGallery            Microsoft Azure PowerShell - Azure Resource Manager and Active Directory cmdlets in Windows PowerShell and...
1.3.0                Az.Security                         PSGallery            Microsoft Azure PowerShell - Azure Security Center cmdlets in Windows PowerShell and PowerShell Core. Allo...
3.0.0                Az.SecurityInsights                 PSGallery            Microsoft Azure PowerShell: SecurityInsights cmdlets                                                         
2.1.0                Az.ServiceBus                       PSGallery            Microsoft Azure PowerShell - Service Bus service cmdlets for Azure Resource Manager in Windows PowerShell ...
3.1.0                Az.ServiceFabric                    PSGallery            Microsoft Azure PowerShell - Service Fabric cmdlets for Azure Resource Manager in Windows PowerShell and P...
1.5.0                Az.SignalR                          PSGallery            Microsoft Azure PowerShell - Azure SignalR service commands for Windows PowerShell and PowerShell Core....   
4.1.0                Az.Sql                              PSGallery            Microsoft Azure PowerShell - SQL service cmdlets for Azure Resource Manager in Windows PowerShell and Powe...
1.1.0                Az.SqlVirtualMachine                PSGallery            Microsoft Azure PowerShell - SqlVirtualMachine service cmdlets for Azure Resource Manager in Windows Power...
1.4.1                Az.StackHCI                         PSGallery            Microsoft Azure PowerShell: StackHci cmdlets                                                                 
5.2.0                Az.Storage                          PSGallery            Microsoft Azure PowerShell - Storage service data plane and management cmdlets for Azure Resource Manager ...
1.7.0                Az.StorageSync                      PSGallery            Microsoft Azure PowerShell - Storage Sync cmdlets in Windows PowerShell and PowerShell Core. Manages opera...
2.0.0                Az.StreamAnalytics                  PSGallery            Microsoft Azure PowerShell: StreamAnalytics cmdlets                                                          
1.0.0                Az.Support                          PSGallery            Microsoft Azure PowerShell - Azure Support cmdlets for Azure Resource Manager in Windows PowerShell and Po...
2.2.0                Az.Synapse                          PSGallery            Microsoft Azure PowerShell - Azure Synapse Analytics in Windows PowerShell and PowerShell Core....           
1.1.0                Az.TrafficManager                   PSGallery            Microsoft Azure PowerShell - Traffic Manager service cmdlets for Azure Resource Manager in Windows PowerSh...
2.12.0               Az.Websites                         PSGallery            Microsoft Azure PowerShell - App Service (Web Apps) service cmdlets for Azure Resource Manager in Windows ...
2.0.2.140            AzureAD                             PSGallery            Azure Active Directory V2 General Availability Module....                                                    
2.0.2.149            AzureADPreview                      PSGallery            Azure Active Directory V2 Preview Module. ...                                                                

PS C:\Windows\system32>

Error output

PS C:\Windows\system32> resolve-azerror
WARNING: The command resolve-azerror is part of Azure PowerShell module "Az.Accounts" and it is not installed. Run "Install-Module Az.Accounts" to install it.
resolve-azerror : The term 'resolve-azerror' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was 
included, verify that the path is correct and try again.
At line:1 char:1
+ resolve-azerror
+ ~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (resolve-azerror:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\Windows\system32>
ghost commented 1 year ago

Thank you for your feedback. This has been routed to the support team for assistance.

navba-MSFT commented 1 year ago

@Obenscripe Thanks for reaching out to us and reporting this issue. We are looking into this issue and we will provide an update.

navba-MSFT commented 1 year ago

@Obenscripe I have installed the same2.11.1version of the Az.Accounts module. But I am unable to reproduce this issue at my end. Could you please try the below steps and let me know if that helps ?

Obenscripe commented 1 year ago

Well I never - I've been having issues with getting a correct and successful AZ connection for a week and this may have sorted it. What I don't understand is that I installed the 2.11.1 module in the first place using Install-module Az.Accounts -allowclobber -Force but it was still giving the error above. Trying again seems to have worked (within this session) - although in fairness i have restarted the box twice this afternoon in order to fix an unrelated issue with SMB. but the restart have have helped. PowerShell_transcript.HOR-UDS-ADM-V01.k9oFCTDV.20230118172914.txt

I'll continue to test with unattended connections as that was where my initial issue was (with version 2.10.4) Why would the -allowclobber -Force not have worked where as re doingt he process today using just -AllowClobber seems on the face of it, to have worked? Thanks Dan

Obenscripe commented 1 year ago

Nope - Ignore me. Whilst that comment above says it worked - and it did. once I closed the ISE then re opened ISE in an elevated session - I always run in an elevated session. I could not repeat the success of just before.

Tihis is the sceen shot showing the error and the dll file failing to be loaded but it does exist. image

And this is weird. closing and window and opening a new elevated ISE I can run it again and now it tells me the module is not installed despite the fact it's installed and imported...

image

I'm out of ideas now.

isra-fel commented 1 year ago

Hi @Obenscripe , first of all, the "module is not installed" message is kind of misleading here. What happened was that the module was installed but failed to be imported. We'll definitely improve the message here.

I doubt there was another module intefering with the import of Az.Accounts. Because we are loading a higher version of Microsoft.Identity.Client.Extensions.Msal.dll than 2.18.4.0. Could you do Get-Module in a new ISE session and share the output?

Also, Resolve-Error isn't going to work because it's inside Az.Accounts. To get more info about the error, let's reproduce the issue by Import-Module Az.Accounts and check the $Error object. Usually we do

$error[0]
$error[0].Exception
$error[0].Exception | Format-List * -Force
$error[0].Exception.InnerException
Obenscripe commented 1 year ago

Hi Isra-fel This is how my code works:

I'm importing the connection code using a module and storing settings in the registry:

function ConnectTo-AzAccount_RSA.GSO.Graph.Access.Reporting{
    [CmdletBinding()]
    param(

    )

    $MSGregCreds = Get-ItemProperty -Path HKCU:\Software\ScheduledScripts\MicrosoftGraph_OAuth2
    $MSGSecurePassword = $MSGregCreds.Thumbprint | ConvertTo-SecureString 
    $MSGrawUsername = $MSGregCreds.AppId
    $MSGcreds = New-Object System.Management.Automation.PSCredential -ArgumentList $MSGrawUsername, $MSGSecurePassword

    $AppId = $MSGcreds.UserName
    $Thumb = $MSGcreds.GetNetworkCredential().Password

    [string] $TenantId = "4dc567e4-2b82-4a00-bcdb-f1f6782a0f6e"  

    #Write-host "ThumbP = $Thumb"
    #Write-host "AppId = $AppId"
    #Write-host "TenantId = $TenantId" 

$AZsession = Connect-AzAccount -CertificateThumbprint $Thumb -ApplicationId $AppId -Tenant $TenantId -ServicePrincipal
return $AZsession
}

and I'm importing that and other modules at the top of my code.

# Sharepoint
Import-Module PnP.PowerShell

### logging functions module ###
Import-Module D:\PowerShell\ScheduledScripts\Utilities\Logging\LoggingFunctions.vProd.psm1

# connections to 365
Import-Module "D:\PowerShell\ScheduledScripts\Utilities\Connect\ConnectToOffice365.vProd.psm1"

# Azure AD Log analytics
import-module Az.OperationalInsights
import-module Az.Accounts

Then calling the connection function

### New Connection
$AZsession = ConnectTo-AzAccount_RSA.GSO.Graph.Access.Reporting

From a new elevated ISE window this morning the issue does not immediately show up:

PS C:\Windows\system32> import-module az.accounts

PS C:\Windows\system32> $Error

PS C:\Windows\system32> $error[0]
$error[0].Exception
$error[0].Exception | Format-List * -Force
$error[0].Exception.InnerException

PS C:\Windows\system32> get-module

ModuleType Version    Name                                ExportedCommands                                                                                                                 
---------- -------    ----                                ----------------                                                                                                                 
Script     2.11.1     az.accounts                         {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault...}                                                         
Script     1.0.0.0    ISE                                 {Get-IseSnippet, Import-IseSnippet, New-IseSnippet}                                                                              
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Content...}                                                               
Manifest   3.0.0.0    Microsoft.PowerShell.Security       {ConvertFrom-SecureString, ConvertTo-SecureString, Get-Acl, Get-AuthenticodeSignature...}                                        
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}                                                                        
Manifest   3.0.0.0    Microsoft.WSMan.Management          {Connect-WSMan, Disable-WSManCredSSP, Disconnect-WSMan, Enable-WSManCredSSP...}                                                  

PS C:\Windows\system32> 

Hmmm, it seems I can't reproduce the issues this morning either. Which is odd because I did reproduce the error several times last night and each time using a new clean elevated ISE window, as I'm doing this morning. This is why this particular issue is frustrating. because It seems fine now but when I trigger my script later from a scheduled task running full unattended (right now I'm running the full script from the file in ISE) It will likely continue to fail. I have to let this run for now but will report back with further testing... Thanks Dan

And sure enough - running as a scheduled task under the same Id As I am logged in with, with highest privilege.. it fails I have attached the two transcript files.

20230119-091604-InvokeKQL.vProd.transcript.log 20230119-091041-InvokeKQL.vProd.transcript.log

As you say, however, we appear to have worked past the first error when trying to import the module. But that still seems to be failing as the Connect command isn't found. the later file has the full exception object. Not sure where to go next? Thanks

isra-fel commented 1 year ago

Hey @Obenscripe Pretty sure there was a conflict between PnP.PowerShell and Az.Accounts, because I can now reproduce by Import-Module PnP.PowerShell; Import-Module Az.Accounts. I need some time to figure out what exactly caused the conflict, but one thing worth trying is to import Az.Accounts before PnP.PowerShell. I wasn't able to reproduce after changing the order.

Obenscripe commented 1 year ago

isra-fel youre a Hero! And you've saved my week!

I swapped the order of the import lines at the top of the script and it's running about 10 minutes already without error. I'll keep an eye for this in other scripts we have as we will be using Az connections more and more. This also explains when I managed to test successfully but then failed when running the prod script unattended because the prod script order was pnp.powershell first. I didn't import the pnp module in all of my testing because that wasn't where the issue appeared to be.

Your're workaround is a complete success. Thanks for this, really appreciate your help. I'll keep an eye on future versions, but with this workaround I can continue. (without thinking I'm going nuts or missing something :-))

Oops, hold on...

The prod script ran successfully until near the end it came up with this error: not seen one like this before when running powershell... The process cannot access the file 'C:\Windows\system32\1' because it is being used by another process.

Message : The process cannot access the file 'C:\Windows\system32\1' because it is being used by another process. Data : {} InnerException : TargetSite : Void WinIOError(Int32, System.String) StackTrace : at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.Management.Automation.PathUtils.MasterStreamOpen(PSCmdlet cmdlet, String filePath, Encoding resolvedEncoding, Boolean defaultEncoding, Boolean Append, Boolean Force, Boolean NoClobber, FileStream& fileStream, StreamWriter& streamWriter, FileInfo& readOnlyFileInfo, Boolean isLiteralPath) HelpLink : Source : mscorlib HResult : -2147024864

Transcript stopped, output file is D:\PowerShell\ScheduledScripts\UpdateGSOCertsSecretsAndAdminSite\Log\20230120-060411-InvokeKQL.vProd.transcript.log

PS C:\Windows\system32>

Got it. I had a panic for a moment there. The scheduled task was still enabled and it over ran my test run in the ISE and clashed writing the log file. Testing again now...

Completeted without issue.! Phew! Thanks isra-fel, it's all good. Cheers Dan

navba-MSFT commented 1 year ago

@Obenscripe Thanks for getting back. We will now proceed with closure of this GitHub issue. If you need any further assistance on this issue in future, please feel free to reopen this thread. We would be happy to help.