msgraph-sdk-powershell
msgraph-sdk-powershell copied to clipboard
get-mguser cmdlet is not working
Getting below error. Please suggest.
PS C:\Windows\system32> Get-MgUser Get-MgUser : Method not found: 'Void Microsoft.Graph.Authentication.AzureIdentityAccessTokenProvider..ctor(Azure.Core.TokenCredential, System.String[], Microsoft.Kiota.Authentication.Azure.ObservabilityOptions, System.String[])'. At line:1 char:1
- Get-MgUser
Modules already installed:
Script 2.19.0 Microsoft.Graph.Authentication {Add-MgEnvironment, Connect-MgGraph, Disconnect-MgGraph, Get-MgContext...}
Script 2.19.0 Microsoft.Graph.Users {Get-MgUser, Get-MgUserCount, Get-MgUserCreatedObject, Get-MgUserCreatedObjectAsServicePrincipal...
@Rajeshwaric7 I'm unable to reproduce this behaviour.
Do you mind sharing the output of Get-InstalledModule Microsoft.Graph.Users
. Please also share what PowerShell version you're using.
@Ndiritu , Please find the requested details.
PS C:\Windows\system32> Get-InstalledModule Microsoft.Graph.Users
Version Name Repository Description
2.19.0 Microsoft.Graph.Users PSGallery Microsoft Graph PowerShell Cmdlets
Powershell version
PS C:\Windows\system32> $PSVersionTable
Name Value
PSVersion 5.1.17763.4974
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.4974
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Also i have tried reinstalling the module and connection is happening successfully.
Connect-MgGraph -TenantId $tenantId -Credential $credential Welcome to Microsoft Graph!
Connected via apponly access using db83b40f-b613-4128-9ac4-4a206f11c6ba Readme: https://aka.ms/graph/sdk/powershell SDK Docs: https://aka.ms/graph/sdk/powershell/docs API Docs: https://aka.ms/graph/docs
NOTE: You can use the -NoWelcome parameter to suppress this message.
This is deeply frustrating since it keeps happening over and over, see https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/2161 https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/2148 https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/2703 and many more where I've also reported this, it's a conflict caused between Graph Authentication and Az module.
As of right now if you want to run an AzurePowerShell@5 task in a DevOps pipeline and you install Graph 2.19 then you get the same error message once you call any Graph command because the Az module will be automatically imported before Graph.
@peombwa @timayabi2020 Hi, could you please check this issue?
FYI, just tested my pipelines and this also happens if I try to install Graph v2.18.
@ricmestre @Rajeshwaric7 Downgrading Microsoft.Graph to 2.17.0 worked for me as a temporary solution.
i have disconnected it, still getting below error during uninstall. PS C:\Windows\system32> Get-InstalledModule Microsoft.Graph.Users | Uninstall-Module -Force WARNING: The version '2.19.0' of module 'Microsoft.Graph.Users' is currently in use. Retry the operation after closing the applications. PackageManagement\Uninstall-Package : Module 'Microsoft.Graph.Users' is in currently in use or you don't have the required permissions. At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.5\PSModule.psm1:12712 char:25
- ... $null = PackageManagement\Uninstall-Package @PSBoundParameters
This is deeply frustrating since it keeps happening over and over, see #2161 #2148 #2703 and many more where I've also reported this, it's a conflict caused between Graph Authentication and Az module.
Having the same issue in our production pipelines since yesterday
Adding weight to this issue as it is causing us significant issues with production systems
I'm having this same issue too with the "Get-MgUser : Method not found: 'Void" error when using the "windows-latest" hosted agent, (which appears to have been recently updated to use v2.19.0 of the Microsoft.Graph.Users module), in an Azure DevOps pipeline.
@Rajeshwaric7 this experience is the same as https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/2703 and currently blocked by https://github.com/Azure/azure-powershell/pull/24609. It's mostly affecting PowerShell 5 users and we are pushing to have it done. In summary, Azure PowerShell needs to bump their Identity assemblies which is most likely causing a conflict with Microsoft Graph identity assemblies. Once that is done you, can go ahead and bump your Az. Accounts version.
Can confirm that this is happening to me as well with Azure Hosted Agents running windows-latest.
Switching to PowershellCore inside the script seems to fix it, but it would be nice not to have to do that.
@ricmestre @Rajeshwaric7 Downgrading Microsoft.Graph to 2.17.0 worked for me as a temporary solution.
Have you downgraded in a Microsoft Hosted agent or a Self Hosted agent? We are unable to downgrade on a MS Hosted agent
Have you downgraded in a Microsoft Hosted agent or a Self Hosted agent? We are unable to downgrade on a MS Hosted agent
The Powershell task should allow you to select a particular version other than latest, regardless of Self Hosted or MS Hosted.
After downgrading to 2.17.0 , i am still getting error:
Connecting to MgGraph: PS C:\Windows\system32> Connect-MgGraph -TenantId $tenantId -Credential $credential Welcome to Microsoft Graph!
Connected via apponly access using db83b40f-b613-4128-9ac4-4a206f11c6ba Readme: https://aka.ms/graph/sdk/powershell SDK Docs: https://aka.ms/graph/sdk/powershell/docs API Docs: https://aka.ms/graph/docs
NOTE: You can use the -NoWelcome parameter to suppress this message.
**PS C:\Windows\system32> Get-MgUser Get-MgUser : One or more errors occurred. At line:1 char:1
- Get-MgUser
-
+ CategoryInfo : NotSpecified: (:) [Get-MgUser_List], AggregateException + FullyQualifiedErrorId : System.AggregateException,Microsoft.Graph.PowerShell.Cmdlets.GetMgUser_List**
PS C:\Windows\system32> Get-InstalledModule Microsoft.Graph.Users
Version Name Repository Description
2.17.0 Microsoft.Graph.Users PSGallery Microsoft Graph PowerShell Cmdlets
Just see that the Azure.Identity module was updated in the upcoming Az 12 release (which shall be released tomorrow by looking at their tag), see https://github.com/Azure/azure-powershell/pull/24609 and https://github.com/Azure/azure-powershell/pull/24792.
CC @Ndiritu, @CarolKigoonya
@Rajeshwaric7 After updating the Az PowerShell module to v12.0.0, the issue is resolved on my end. Would you kindly validate this on your side?
C:\Users\<username>> Get-InstalledModule -Name "Az"
Version Name Repository Description
------- ---- ---------- -----------
12.0.0 Az PSGallery Microsoft Azure PowerShell - Cmdlets to manage resources in Azure. This module is co...
C:\Users\<username>> Get-InstalledModule -Name "Microsoft.Graph"
Version Name Repository Description
------- ---- ---------- -----------
2.19.0 Microsoft.Graph PSGallery Microsoft Graph PowerShell module
C:\Users\<username>> Import-Module Az.Accounts
C:\Users\<username>> Import-Module Microsoft.Graph.Authentication
C:\Users\<username>> Import-Module Microsoft.Graph.Users
C:\Users\<username>> Get-MgUser
DisplayName Id Mail UserPrincipalName
----------- -- ---- -----------------
@Ndiritu
PS C:\Windows\system32> Get-InstalledModule -Name "Az.accounts"
Version Name Repository Description
3.0.0 Az.Accounts PSGallery Microsoft Azure PowerShell - Accounts credential management cmdlets for Azure Resource M...
PS C:\Windows\system32> Get-InstalledModule -Name "Microsoft.Graph.users"
Version Name Repository Description
2.19.0 Microsoft.Graph.Users PSGallery Microsoft Graph PowerShell Cmdlets
Still getting same error:
PS C:\Windows\system32> Get-MgUser Get-MgUser : One or more errors occurred. At line:1 char:1
- Get-MgUser
-
+ CategoryInfo : NotSpecified: (:)
it worked in Powershell 7 version.
@Rajeshwaric7
Are you able to check the version of Az powershell in use?
Get-InstalledModule -Name "Az"
and update to 12.0.0 if it's not the current version?
@Ndiritu , I did tried "Update-Module -Name Az -Force" yesterday and unable to pull the version of the AZ powershell. PS C:\Windows\system32> Get-InstalledModule -Name "Az" PackageManagement\Get-Package : No match was found for the specified search criteria and module names 'Az'. At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.5\PSModule.psm1:9445 char:9
-
PackageManagement\Get-Package @PSBoundParameters | Microsoft. ...
Thanks for sharing @Rajeshwaric7. I notice from an earlier message that you have Az.Accounts
3.0.0
which is the latest available. Looking further into this.
@Rajeshwaric7 still unable to reproduce this. Would you mind sharing more about your environment? Are you running this on local/Azure pipelines? Are you able to reset your environment/start the installations afresh and share any screenshots/logs?
@Rajeshwaric7 please run this command in your powershell session and share the output.
[System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object Location | Sort-Object -Property FullName | Select-Object -Property FullName, Location | Out-GridView
I am using powershell app and Powershell ISE on test Windows server 2019.
@Rajeshwaric7 from the screenshot, you still have version conflicts of Azure.Identity
and Azure.Identity.Broker
assemblies. Is it possible to remove the old Az.Accounts
module? i.e. Completely remove Version 2.19.0 which will prevent the old assemblies from being loaded in the session.
Team, Still same issue even after uninstalling and installing the az.accounts module.
PS C:\Windows\system32> Get-InstalledModule -Name "Az.accounts" -AllVersions
Version Name Repository Description
3.0.0 Az.Accounts PSGallery Microsoft Azure PowerShell - Accounts credential management cmdlets for Azure Resource Manager in Windows PowerShell and PowerShell Core....
Getting this error for "Connect-AzAccount" when i run on PS7 Connect-AzAccount -TenantId $tenantId -Credential $credential Connect-AzAccount: UsernamePasswordCredential authentication failed: Unsupported User Type 'Unknown'. Please see https://aka.ms/msal-net-up. See the troubleshooting guide for more information. https://aka.ms/azsdk/net/identity/usernamepasswordcredential/troubleshoot Could not find tenant id for provided tenant domain '976ace6a-6df4-47c0-9e7f-64dde4491107'. Please ensure that the provided user is
If i run run same on PS 5.1 PS C:\Windows\system32> Connect-AzAccount -TenantId $tenantId -Credential $credential Connect-AzAccount : Method not found: 'System.Threading.Tasks.Task`1<Azure.Identity.AuthenticationRecord> Azure.Identity.UsernamePasswordCredential.AuthenticateAsync(Azure.Core.TokenRequestContext, System.Threading.CancellationToken)'. Could not find tenant id for provided tenant domain '976ace6a-6df4-47c0-9e7f-64dde4491107'. Please ensure that the provided user is found in the provided tenant domain. At line:1 char:1
- Connect-AzAccount -TenantId $tenantId -Credential $credential
-
+ CategoryInfo : CloseError: (:) [Connect-AzAccount], ArgumentNullException + FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand
Hey @Rajeshwaric7 - I think the missing link here is how PowerShell modules are saved depending on what version of PowerShell you're running (5.1 vs 7) and the scope of the install (AllUsers
vs CurrentUser
)
I suggest doing the following to make sure you do not have conflicts. This will probably make some MSFT people squirm, but hey... that's what I do best:
Purge Windows PowerShell 5.1 modules
- Browse to
C:\Users\USERNAME\Documents\WindowsPowerShell\Modules
and delete the entireAz.Accounts
folder - Browse to
C:\Program Files\WindowsPowerShell\Modules
and delete the entireAz.Accounts
folder
Purge PowerShell 7 modules
- Browse to
C:\Users\USERNAME\Documents\PowerShell\Modules
and delete the entireAz.Accounts
folder - Browse to
C:\Program Files\PowerShell\7\Modules
and delete the entireAz.Accounts
folder
Once that's done, close all open PowerShell windows and Windows Terminal windows... and then reinstall the module in both PowerShell 5.1 and pwsh 7 sessions using the -Scope CurrentUser
option. That will limit your testing further to just your user (in case you're on a shared machine).
It worked now, Thanks :)