Get-MgUser : The term 'Get-MgUser' 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

Yucel Osmanoglu 25 Reputation points
2023-05-11T09:31:13.8066667+00:00

Dear All,

I have been trouble with Microsoft Graph Powershell even i installed microsoft.graph module but it doesn't recognized the powershell codes. So that how can i fix that problem? Kindly, can you enlighten to me?

PS C:\Windows\system32>

Install-Module -Name "Microsoft.Graph"

Untrusted repository

You are installing the modules from an untrusted repository. If you trust this repository, change its

InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from

'PSGallery'?

[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): A

PS C:\Windows\system32> Install-Module Microsoft.Graph -Scope CurrentUser

Untrusted repository

You are installing the modules from an untrusted repository. If you trust this repository, change its

InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from

'PSGallery'?

[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): A

PS C:\Windows\system32> Connect-MgGraph -Scopes "User.Read.All"

Welcome To Microsoft Graph!

PS C:\Windows\system32> $users = Get-MgUser

$users | Select-Object DisplayName, UserPrincipalName, Mail

Get-MgUser : The term 'Get-MgUser' 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:2 char:10
+ $users = Get-MgUser
+          ~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-MgUser:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
PS C:\Windows\system32> Connect-MgGraph -Scopes "User.Read.All", "Group.ReadWrite.All"
Welcome To Microsoft Graph!
PS C:\Windows\system32> $users = Get-MgUser
Get-MgUser : The term 'Get-MgUser' 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:10
+ $users = Get-MgUser
+          ~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-MgUser:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,445 questions
0 comments No comments
{count} votes

6 answers

Sort by: Most helpful
  1. TH-4749-MSFT 3,295 Reputation points
    2023-05-11T16:01:04.7966667+00:00

    Hello Yucel Osmanoglu,

    Thanks for your reply. based on the Get-ExecutionPolicy -List output you have unrestricted access to running to both current user and local machine. Please provide output of the 'Get-InstalledModule Microsoft.Graph' command to assist you further.

    Thanks.

    1 person found this answer helpful.

  2. rosskoes05 5 Reputation points
    2023-10-05T15:29:52.1966667+00:00

    How did you resolve it?

    1 person found this answer helpful.
    0 comments No comments

  3. TH-4749-MSFT 3,295 Reputation points
    2023-05-11T14:47:51.3366667+00:00

    Hello Yucel Osmanoglu,

    Thanks for reaching out. The issue you are experiencing could likely be due to PowerShell execution policy is blocking the execution of scripts. Please run the 'Get-ExecutionPolicy -List' command to check your execution policy and verify in the command output if CurrentUser or LocalMachine policies and not Restricted. You can use the 'Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process' to provide minimum permission to run the command.

    Additionally, please run the 'Get-InstalledModule Microsoft.Graph; command and provide the output if you are still experiencing the issue after following the above steps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.

    Thanks.


  4. Yucel Osmanoglu 25 Reputation points
    2023-05-11T15:12:32.8266667+00:00

    Hi,

    Thanks for above explanation.

    How can i enable to MachinePolicy and UserPolicy because i have seen still same error.

    PS C:\Windows\system32> Get-ExecutionPolicy -List
    
            Scope ExecutionPolicy
            ----- ---------------
    MachinePolicy       Undefined
       UserPolicy       Undefined
          Process    Unrestricted
      CurrentUser    Unrestricted
     LocalMachine    Unrestricted
    
    
    PS C:\Windows\system32> Get-MGuser -All -Property UserPrincipalName, PasswordPolicies | Select-Object UserprincipalName,@{
    >>     N="PasswordNeverExpires";E={$_.PasswordPolicies -contains "DisablePasswordExpiration"}
    >>  }
    Get-MGuser : The term 'Get-MGuser' 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
    + Get-MGuser -All -Property UserPrincipalName, PasswordPolicies | Selec ...
    + ~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (Get-MGuser:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException
    
    PS C:\Windows\system32>
    
    
    0 comments No comments

  5. Siva Bandarupalli 0 Reputation points
    2023-09-21T18:47:18.1766667+00:00

    Has this been resolved ? If so, could you pls provide some insights, thank you