New-MgRoleAssignment -PrincipalId "your-object-id" -RoleDefinitionId "62e90394-69f5-4237-9190-012177145e10"

Kotagi, Veeresh 0 Reputation points
2025-04-09T17:23:25.34+00:00

PS C:\Users\vkotagi> Connect-MgGraph -Scopes "RoleManagement.ReadWrite.Directory"

Connect-MgGraph : The term 'Connect-MgGraph' 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

  • Connect-MgGraph -Scopes "RoleManagement.ReadWrite.Directory"
  • 
        + CategoryInfo          : ObjectNotFound: (Connect-MgGraph:String) [], CommandNotFoundException
    
        + FullyQualifiedErrorId : CommandNotFoundException
    
    

PS C:\Users\vkotagi> New-MgRoleAssignment -PrincipalId "your-object-id" -RoleDefinitionId "62e90394-69f5-4237-9190-012177145e10"

New-MgRoleAssignment : The term 'New-MgRoleAssignment' 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

  • New-MgRoleAssignment -PrincipalId "your-object-id" -RoleDefinitionId ...
  • 
        + CategoryInfo          : ObjectNotFound: (New-MgRoleAssignment:String) [], CommandNotFoundException
    
        + FullyQualifiedErrorId : CommandNotFoundException
    
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
24,202 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Kancharla Saiteja 3,165 Reputation points Microsoft External Staff
    2025-04-09T18:54:40.8566667+00:00

    Hi @Kotagi, Veeresh,

    Based on your query, here is my understanding: You are unable to perform role assignment using Microsoft graph PowerShell.

    The error of term not recognized for Connect-MgGraph comes up when the module is not found. To avoid this error, you need to first install the module in your PowerShell. Check the prerequisites which are required to install Microsoft graph PowerShell SDK. Make sure you have

    1. Upgrade to PowerShell 5.1 or later
    2. Install .NET Framework 4.7.2 or later

    Now open PowerShell as administrator set the PowerShell Execution policy to remotesigned or lessrestrictive using the following command:

    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser Installation command: Install-Module Microsoft.Graph -Scope CurrentUser -Repository PSGallery -Force

    Check the installation: Get-InstalledModule Microsoft.Graph

    Installation guide documentation: Install the Microsoft Graph PowerShell SDK.

    Connect MgGraph: Connect-MgGraph -Scopes "RoleManagement.ReadWrite.Directory"

    The scopes are the permissions which are required to manage the particular feature. In this situation, you are connecting to role management, so provided the scope accordingly.

    Documentation to connect MgGraph with various scopes: Connect-MgGraph.

    Based on the command, I understood you are performing role assignments, here is the documentation for the role assignments: Assign Microsoft Entra roles in Privileged Identity Management using Microsoft Graph PowerShell.

    Here are the primary prerequisites: Privileged Role Administrator role and Microsoft Entra ID P2 or Enterprise Mobility + Security (EMS) E5 license. If you do not have any of the prerequisites, you will not be able to perform the operations.

    Example for assignment of role:

    $params = @{
      "PrincipalId" = "d29e358a-a443-4d83-98b3-499a5405bb5b"
      "RoleDefinitionId" = "88d8e3e3-8f55-4a1e-953a-9b9898b8876b"
      "Justification" = "Add eligible assignment"
      "DirectoryScopeId" = "/"
      "Action" = "AdminAssign"
      "ScheduleInfo" = @{
        "StartDateTime" = Get-Date
        "Expiration" = @{
          "Type" = "AfterDuration"
          "Duration" = "PT10H"
          }
        }
       }
    New-MgRoleManagementDirectoryRoleEligibilityScheduleRequest -BodyParameter $params | 
      Format-List Id, Status, Action, AppScopeId, DirectoryScopeId, RoleDefinitionId, IsValidationOnly, Justification, PrincipalId, CompletedDateTime, CreatedDateTime
    

    I hope this information is helpful. Please feel free to reach out if you have any further questions.

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


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.