Closed peterboba closed 1 year ago
Additionally - if the module import order is reversed, Az cmdlets don't work
Import-Module Microsoft.Graph.Authentication
Connect-AzAccount
WARNING: Unable to acquire token for tenant 'organizations' with error 'Method not found:
'System.Threading.Tasks.Task`1<Azure.Identity.AuthenticationRecord>
Azure.Identity.InteractiveBrowserCredential.AuthenticateAsync(Azure.Core.TokenRequestContext,
System.Threading.CancellationToken)'.'
Connect-AzAccount : Method not found: 'System.Threading.Tasks.Task`1<Azure.Identity.AuthenticationRecord>
Azure.Identity.InteractiveBrowserCredential.AuthenticateAsync(Azure.Core.TokenRequestContext,
System.Threading.CancellationToken)'.
At line:1 char:1
+ Connect-AzAccount
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Connect-AzAccount], MissingMethodException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand
Get-MgApplication
Get-MgApplication : Authentication needed. Please call Connect-MgGraph.
At line:1 char:1
+ Get-MgApplication
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-MgApplication_List], AuthenticationException
+ FullyQualifiedErrorId : Microsoft.Graph.PowerShell.Cmdlets.GetMgApplication_List
This issue is similar to https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/2147
This also impacts the Azure DevOps Pipeline agents unfortunately
We are impacted by this as well in our pipelines. Haven't found a solution yet..
We are also impacted, our script is using the "New-MgGroupOwnerByRef -GroupId $groupId -BodyParameter
UPDATE: If you're not using the -UseDeviceAuthentication in your Connect-MgGraph command is not using this flag, it will automatically fallback. It's a feature from the new version.
Thanks for bringing this to our attention, and sorry for any inconvenience caused in your upgrade from v1.x to v2.x.
Our preliminary investigation points to an assembly conflict with the latest version of Az.Accounts
module (v2.12.2+), which unfortunately is a well-known problem with PowerShell 5.1 - https://learn.microsoft.com/en-us/powershell/scripting/dev-cross-plat/resolving-dependency-conflicts.
As workaround, you can consider the following options as we further investigate and try to get to the root cause of the conflict:
Az.Accounts
v2.12.1 as instructed at https://github.com/Azure/azure-powershell/issues/21647#issuecomment-1521820690:
PS C:\> Import-Module Az.Accounts -RequiredVersion 2.12.1 # Rollback to Az.Accounts 2.12.1
PS C:\> Import-Module Microsoft.Graph.Authentication
PS C:\> Get-MgApplication
Get-MgApplication : Authentication needed. Please call Connect-MgGraph.
@peombwa thanks for responding. Do you know if we have a workaround for this issue in AzurePowerShell@5 task?
thanks for responding. Do you know if we have a workaround for this issue in AzurePowerShell@5 task?
You can try updating AzurePowerShell@5
task to use PowerShell 7 by setting pwsh: true
as described at https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/azure-powershell-v5?view=azure-pipelines:
- task: AzurePowerShell@5
inputs:
azureSubscription: '$(AZURE_SUBSCRIPTION)'
azurePowerShellVersion: LatestVersion
ScriptType: 'InlineScript'
pwsh: true # Set to true to use PowerShell 7.
Inline: |
Connect-MgGraph ...
You can also use azurePowerShellVersion
option on the lock the Az SDK version.
We’ve just shipped v2.1.0, which should address the assembly conflict with the latest versions of Az modules in PowerShell 5.1. Please update to v2.1.0 and let us know if it resolves the issue - https://github.com/microsoftgraph/msgraph-sdk-powershell/releases/tag/2.1.0.
We’ve just shipped v2.1.0, which should address the assembly conflict with the latest versions of Az modules in PowerShell 5.1. Please update to v2.1.0 and let us know if it resolves the issue - https://github.com/microsoftgraph/msgraph-sdk-powershell/releases/tag/2.1.0.
I have confirmed this is work although with some limitations:
Connect-AzAccount
FIRST now else you will encounter the error that AzureAccount does not work due to dependency issues. This is a bug that should be fixed on Az-powershell-sdkI have not found any other issue yet.
~LvdW
We’ve just shipped v2.1.0, which should address the assembly conflict with the latest versions of Az modules in PowerShell 5.1. Please update to v2.1.0 and let us know if it resolves the issue - https://github.com/microsoftgraph/msgraph-sdk-powershell/releases/tag/2.1.0.
I have confirmed this is work although with some limitations:
- You HAVE to run
Connect-AzAccount
FIRST now else you will encounter the error that AzureAccount does not work due to dependency issues. This is a bug that should be fixed on Az-powershell-sdkI have not found any other issue yet.
~LvdW
Thanks for this information. I was having issues with Az and Graph commands even after the update in azurepowershell@5
task. I fixed it by moving to pwsh
7 task instead, but I will give this a go.
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.
You can try updating AzurePowerShell@5 task to use PowerShell 7 by setting pwsh: true
For those who cannot immediately upgrade to Mg 2.1.0 and are looking at using Powershell Core in their ADO pipelines instead as a workaround, please be aware of an open problem with the AzurePowerShell@5 task under pwsh 7.3 - Service Connections configured to use client certificate authentication cannot be used, because the task incorrectly passes a file path internally to openssl.exe.
Apart from that issue, I can confirm that Az 9.6.0 and Mg 2.0.0 work in perfect harmony in our pipelines under pwsh.
I was originally bought here from this issue https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/2161
I wasn't too happy with pinning a version to this install IF Powershell 5.x was the issue (as suggested: Install-Module Microsoft.Graph -RequiredVersion 2.1.0 -Force -AllowClobber) so I went down the route of adding pwsh:true to the AzurePowerShell@5 pipeline task - which was an excellent suggestion.
When running on an Azure DevOps hosted pipeline agent using "windows-latest" however, for some reason the Microsoft.Graph module isn't installed for use with PowerShell 7 (like it was with PowerShell 5) so I have to install the module as part of the deployment now - which adds another 20 MINUTES to the runtime whilst it installs it - despite mentions the overall time would be reduced - it's actually increased! https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/134
All this to run a single "Update-MgApplication" in my pipeline - what a price to progress eh?
We’ve just shipped v2.1.0, which should address the assembly conflict with the latest versions of Az modules in PowerShell 5.1. Please update to v2.1.0 and let us know if it resolves the issue - https://github.com/microsoftgraph/msgraph-sdk-powershell/releases/tag/2.1.0.
I didn't have a chance to reply earlier. Thanks for fixing this! I can confirm that I don't see the same issue with v2.1.0
(with possible limitation)
You HAVE to run Connect-AzAccount FIRST now else you will encounter the error that AzureAccount does not work due to dependency issues. This is a bug that should be fixed on Az-powershell-sdk
Still having the issue on Windows Powershell 5.1. Get-InstalledModule yields this:
Version Name Repository Description
------- ---- ---------- -----------
10.4.1 Az PSGallery Microsoft Azure PowerShell - Cmdlets t...
2.13.1 Az.Accounts PSGallery Microsoft Azure PowerShell - Accounts ...
2.0.0 Az.Advisor PSGallery Microsoft Azure PowerShell: Advisor cm...
5.5.1 Az.Aks PSGallery Microsoft Azure PowerShell - Azure man...
1.1.4 Az.AnalysisServices PSGallery Microsoft Azure PowerShell - Analysis ...
4.0.2 Az.ApiManagement PSGallery Microsoft Azure PowerShell - Api Manag...
1.3.0 Az.AppConfiguration PSGallery Microsoft Azure PowerShell: AppConfigu...
2.2.2 Az.ApplicationInsights PSGallery Microsoft Azure PowerShell: Applicatio...
1.0.0 Az.ArcResourceBridge PSGallery Microsoft Azure PowerShell: ArcResourc...
2.0.0 Az.Attestation PSGallery Microsoft Azure PowerShell - Attestati...
1.0.0 Az.Automanage PSGallery Microsoft Azure PowerShell: Automanage...
1.9.1 Az.Automation PSGallery Microsoft Azure PowerShell - Automatio...
3.5.0 Az.Batch PSGallery Microsoft Azure PowerShell - Batch ser...
2.0.3 Az.Billing PSGallery Microsoft Azure PowerShell - Billing s...
3.1.1 Az.Cdn PSGallery Microsoft Azure PowerShell: Cdn cmdlets
1.2.0 Az.CloudService PSGallery Microsoft Azure PowerShell: CloudServi...
1.14.0 Az.CognitiveServices PSGallery Microsoft Azure PowerShell - Cognitive...
6.3.0 Az.Compute PSGallery Microsoft Azure PowerShell - Compute s...
1.0.0 Az.ConfidentialLedger PSGallery Microsoft Azure PowerShell: Confidenti...
3.2.2 Az.ContainerInstance PSGallery Microsoft Azure PowerShell: ContainerI...
4.1.1 Az.ContainerRegistry PSGallery Microsoft Azure PowerShell - Container...
1.12.0 Az.CosmosDB PSGallery Microsoft Azure PowerShell - CosmosDB ...
1.1.0 Az.DataBoxEdge PSGallery Microsoft Azure PowerShell - DataBoxEd...
1.7.0 Az.Databricks PSGallery Microsoft Azure PowerShell: Databricks...
1.17.0 Az.DataFactory PSGallery Microsoft Azure PowerShell - Data Fact...
1.0.3 Az.DataLakeAnalytics PSGallery Microsoft Azure PowerShell - Data Lake...
1.3.0 Az.DataLakeStore PSGallery Microsoft Azure PowerShell - Azure Dat...
2.1.0 Az.DataProtection PSGallery Microsoft Azure PowerShell: DataProtec...
1.0.1 Az.DataShare PSGallery Microsoft Azure PowerShell - DataShare...
1.1.0 Az.DeploymentManager PSGallery PowerShell .Net Core Microsoft Azure P...
4.0.0 Az.DesktopVirtualization PSGallery Microsoft Azure PowerShell: DesktopVir...
1.0.2 Az.DevTestLabs PSGallery Microsoft Azure PowerShell - DevTest L...
1.1.3 Az.Dns PSGallery Microsoft Azure PowerShell - DNS servi...
1.6.0 Az.EventGrid PSGallery Microsoft Azure PowerShell - Event Gri...
4.1.0 Az.EventHub PSGallery Microsoft Azure PowerShell - Event Hub...
1.10.0 Az.FrontDoor PSGallery Microsoft Azure PowerShell - Front Doo...
4.0.6 Az.Functions PSGallery Microsoft Azure PowerShell - Azure Fun...
6.0.1 Az.HDInsight PSGallery Microsoft Azure PowerShell - HDInsight...
2.0.0 Az.HealthcareApis PSGallery Microsoft Azure PowerShell: Healthcare...
2.7.5 Az.IotHub PSGallery Microsoft Azure PowerShell - IoT Hub s...
4.12.0 Az.KeyVault PSGallery Microsoft Azure PowerShell - Key Vault...
2.2.0 Az.Kusto PSGallery Microsoft Azure PowerShell: Kusto cmdlets
1.0.0 Az.LoadTesting PSGallery Microsoft Azure PowerShell: LoadTestin...
1.5.0 Az.LogicApp PSGallery Microsoft Azure PowerShell - Logic App...
1.1.3 Az.MachineLearning PSGallery Microsoft Azure PowerShell - Machine L...
1.0.0 Az.MachineLearningServices PSGallery Microsoft Azure PowerShell: MachineLea...
1.3.1 Az.Maintenance PSGallery Microsoft Azure PowerShell - Maintenan...
1.1.1 Az.ManagedServiceIdentity PSGallery Microsoft Azure PowerShell: ManagedSer...
3.0.0 Az.ManagedServices PSGallery Microsoft Azure PowerShell: ManagedSer...
2.0.0 Az.MarketplaceOrdering PSGallery Microsoft Azure PowerShell: Marketplac...
1.1.2 Az.Media PSGallery Microsoft Azure PowerShell - Media ser...
2.2.0 Az.Migrate PSGallery Microsoft Azure PowerShell: Migrate cm...
4.6.0 Az.Monitor PSGallery Microsoft Azure PowerShell - Monitor s...
1.1.1 Az.MySql PSGallery Microsoft Azure PowerShell: MySql cmdlets
6.2.0 Az.Network PSGallery Microsoft Azure PowerShell - Networkin...
1.1.2 Az.NotificationHubs PSGallery Microsoft Azure PowerShell - Notificat...
3.2.0 Az.OperationalInsights PSGallery Microsoft Azure PowerShell - Operation...
1.6.3 Az.PolicyInsights PSGallery Microsoft Azure PowerShell - Azure Pol...
1.1.0 Az.PostgreSql PSGallery Microsoft Azure PowerShell: PostgreSql...
1.2.1 Az.PowerBIEmbedded PSGallery Microsoft Azure PowerShell - Power BI ...
1.0.4 Az.PrivateDns PSGallery Microsoft Azure PowerShell - Private D...
6.6.0 Az.RecoveryServices PSGallery Microsoft Azure PowerShell - Recovery ...
1.8.0 Az.RedisCache PSGallery Microsoft Azure PowerShell - Redis Cac...
1.2.0 Az.RedisEnterpriseCache PSGallery Microsoft Azure PowerShell: RedisEnter...
2.0.0 Az.Relay PSGallery Microsoft Azure PowerShell: Relay cmdlets
1.2.0 Az.ResourceMover PSGallery Microsoft Azure PowerShell: ResourceMo...
6.11.1 Az.Resources PSGallery Microsoft Azure PowerShell - Azure Res...
1.4.0 Az.Security PSGallery Microsoft Azure PowerShell - Azure Sec...
3.1.0 Az.SecurityInsights PSGallery Microsoft Azure PowerShell: SecurityIn...
3.0.0 Az.ServiceBus PSGallery Microsoft Azure PowerShell - Service B...
3.2.0 Az.ServiceFabric PSGallery Microsoft Azure PowerShell - Service F...
2.0.0 Az.SignalR PSGallery Microsoft Azure PowerShell - Azure Sig...
4.10.0 Az.Sql PSGallery Microsoft Azure PowerShell - SQL servi...
2.1.0 Az.SqlVirtualMachine PSGallery Microsoft Azure PowerShell: SqlVirtual...
2.2.0 Az.StackHCI PSGallery Microsoft Azure PowerShell: StackHci c...
5.10.1 Az.Storage PSGallery Microsoft Azure PowerShell - Storage s...
1.0.1 Az.StorageMover PSGallery Microsoft Azure PowerShell: StorageMov...
2.0.0 Az.StorageSync PSGallery Microsoft Azure PowerShell - Storage S...
2.0.0 Az.StreamAnalytics PSGallery Microsoft Azure PowerShell: StreamAnal...
1.0.0 Az.Support PSGallery Microsoft Azure PowerShell - Azure Sup...
3.0.3 Az.Synapse PSGallery Microsoft Azure PowerShell - Azure Syn...
1.2.1 Az.TrafficManager PSGallery Microsoft Azure PowerShell - Traffic M...
3.1.1 Az.Websites PSGallery Microsoft Azure PowerShell - App Servi...
2.0.2.182 AzureAD PSGallery Azure Active Directory V2 General Avai...
2.6.1 Microsoft.Graph.Authentication PSGallery Microsoft Graph PowerShell Authenticat...
2.6.1 Microsoft.Graph.Identity.Directo... PSGallery Microsoft Graph PowerShell Cmdlets
1.1.183.66 MSOnline PSGallery Microsoft Azure Active Directory Modul...
1.4.8.1 PackageManagement PSGallery PackageManagement (a.k.a. OneGet) is a...
2.2.5 PowerShellGet PSGallery PowerShell module with commands for di...
2.6.1 Microsoft.Graph PSGallery Microsoft Graph PowerShell module
2.6.1 Microsoft.Graph.Applications PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.Bookings PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.Calendar PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.ChangeNotifications PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.CloudCommunications PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.Compliance PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.CrossDeviceExper... PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.DeviceManagement PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.DeviceManagement... PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.DeviceManagement... PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.DeviceManagement... PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.DeviceManagement... PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.Devices.CloudPrint PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.Devices.Corporat... PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.Devices.ServiceA... PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.DirectoryObjects PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.Education PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.Files PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.Groups PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.Identity.Governance PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.Identity.Partner PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.Identity.SignIns PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.Mail PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.Notes PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.People PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.PersonalContacts PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.Planner PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.Reports PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.SchemaExtensions PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.Search PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.Security PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.Sites PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.Teams PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.Users PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.Users.Actions PSGallery Microsoft Graph PowerShell Cmdlets
2.6.1 Microsoft.Graph.Users.Functions PSGallery Microsoft Graph PowerShell Cmdlets
A script that uses both Az and MSGraph that I am now trying to run can be found here: https://github.com/briandelmsft/SentinelAutomationModules/blob/main/Deploy/GrantPermissions.ps1
It fails with
[+] Connect to the Azure AD tenant: <REDACTED>
Connect-MgGraph : The type initializer for 'Azure.Identity.AuthenticationRecord' threw an exception.
At C:\Users\<REDACTED>\Downloads\<REDACTED>.ps1:49 char:1
+ Connect-MgGraph -TenantId $TenantId -Scopes AppRoleAssignment.ReadWri ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Connect-MgGraph], TypeInitializationException
+ FullyQualifiedErrorId : Microsoft.Graph.PowerShell.Authentication.Cmdlets.ConnectMgGraph
[+] Connecting to to the Azure subscription: <REDACTED>
[-] Login to Azure Management failed. Method not found: 'System.Threading.Tasks.Task`1<Azure.Identity.AuthenticationRecord> Azure.Identity.InteractiveBrowserCredential.AuthenticateAsync(Azure.Core.TokenRequestContext, System.Threading.CancellationToken)'.
Could not find tenant id for provided tenant domain '<REDACTED>'. Please ensure that the provided user is found in the provided tenant domain.
[+] Setting permission Data.Read on Get-UEBAInsights
Get-MgServicePrincipal : Authentication needed. Please call Connect-MgGraph.
I have tried running Update-Module on both Az and Graph. I have also tried to install .NET Framework 4.8.1 and 7.0, no effect.
I had this issue for months. Finally found that the Azure.core dll was being loaded by the SQLServer powershell module. I removed the SQLServer ps module and Graph authentication has been working perfectly so far.
Describe the bug There seems to be an assembly conflict when using Az and Microsoft.Graph 2.0.0 Powershell modules in the same session. This was not a problem with the previous version of Microsoft.Graph Powershell. Brief investigation shows that this might be an issue with incompatible Azure.Identity (or Azure.Core) dll introduced in 2.0.0 version of Microsoft.Graph Powershell.
This is quite an problem for us as we need to use Powershell 5.1 and the mentioned modules together.
It doesn't look like the fix below solves the issue. https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/1880 https://github.com/microsoftgraph/msgraph-sdk-powershell/pull/1894
To Reproduce Steps to reproduce the behavior:
Expected behavior
Debug Output Bad outcome
Expected outcome
Module Version
Environment Data
Additional Context