Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get-mguser cmdlet is not working #2745

Closed
Rajeshwaric7 opened this issue May 15, 2024 · 30 comments
Closed

get-mguser cmdlet is not working #2745

Rajeshwaric7 opened this issue May 15, 2024 · 30 comments
Assignees
Labels
priority:p0 Blocking issue. Loss of critical functions eg security/privacy violation. Bug SLA<=48hrs Resolved: Awaiting Deployment type:bug A broken experience

Comments

@Rajeshwaric7
Copy link

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 Rajeshwaric7 added the status:waiting-for-triage An issue that is yet to be reviewed or assigned label May 15, 2024
@Ndiritu
Copy link
Contributor

Ndiritu commented May 15, 2024

@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 Ndiritu added type:question An issue that's a question Needs: Author Feedback and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned labels May 15, 2024
@Rajeshwaric7
Copy link
Author

@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

@Rajeshwaric7
Copy link
Author

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.

@ricmestre
Copy link

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.

@ricmestre
Copy link

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.

@ricmestre
Copy link

ricmestre commented May 15, 2024

@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.

@michalkrzych
Copy link

@ricmestre @Rajeshwaric7 Downgrading Microsoft.Graph to 2.17.0 worked for me as a temporary solution.

@Rajeshwaric7
Copy link
Author

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

@TomSzaky
Copy link

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

@jacehoyle
Copy link

Adding weight to this issue as it is causing us significant issues with production systems

@amwuk
Copy link

amwuk commented May 16, 2024

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.

@timayabi2020
Copy link
Collaborator

@Rajeshwaric7 this experience is the same as #2703 and currently blocked by Azure/azure-powershell#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.

@TheKrisSodroski
Copy link

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.

@TomSzaky
Copy link

TomSzaky commented May 17, 2024

@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

@TheKrisSodroski
Copy link

TheKrisSodroski commented May 17, 2024

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.

@Rajeshwaric7
Copy link
Author

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

@petrhollayms
Copy link

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 Azure/azure-powershell#24609 and Azure/azure-powershell#24792.

CC @Ndiritu, @CarolKigoonya

@petrhollayms petrhollayms added Resolved: Awaiting Deployment type:bug A broken experience priority:p0 Blocking issue. Loss of critical functions eg security/privacy violation. Bug SLA<=48hrs and removed type:question An issue that's a question labels May 20, 2024
@Ndiritu
Copy link
Contributor

Ndiritu commented May 22, 2024

@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
-----------       --                                   ----                               -----------------

@Rajeshwaric7
Copy link
Author

@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: (:)
    

@Rajeshwaric7
Copy link
Author

it worked in Powershell 7 version.

@Ndiritu
Copy link
Contributor

Ndiritu commented May 22, 2024

@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?

@Rajeshwaric7
Copy link
Author

@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. ...
    

@Ndiritu
Copy link
Contributor

Ndiritu commented May 23, 2024

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.

@Ndiritu
Copy link
Contributor

Ndiritu commented May 23, 2024

@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?

@timayabi2020
Copy link
Collaborator

timayabi2020 commented May 24, 2024

@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

@Rajeshwaric7
Copy link
Author

I am using powershell app and Powershell ISE on test Windows server 2019.
image

@timayabi2020
Copy link
Collaborator

@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.

@Rajeshwaric7
Copy link
Author

Rajeshwaric7 commented May 24, 2024

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
    

@eponerine
Copy link

eponerine commented May 24, 2024

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

  1. Browse to C:\Users\USERNAME\Documents\WindowsPowerShell\Modules and delete the entire Az.Accounts folder
  2. Browse to C:\Program Files\WindowsPowerShell\Modules and delete the entire Az.Accounts folder

Purge PowerShell 7 modules

  1. Browse to C:\Users\USERNAME\Documents\PowerShell\Modules and delete the entire Az.Accounts folder
  2. Browse to C:\Program Files\PowerShell\7\Modules and delete the entire Az.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).

@Rajeshwaric7
Copy link
Author

It worked now, Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority:p0 Blocking issue. Loss of critical functions eg security/privacy violation. Bug SLA<=48hrs Resolved: Awaiting Deployment type:bug A broken experience
Projects
None yet
Development

No branches or pull requests