1

Unable to execute Get-AzureADMSPrivilegedRoleAssignment in powershell its giving me an error as Get-AzureADMSPrivilegedRoleAssignment : The term 'Get-AzureADMSPrivilegedRoleAssignment' is not recognized

I tried installing AzureADPreview module, it says the module already present, but still am getting this error.

Get-AzureADMSPrivilegedRoleAssignment : The term 'Get-AzureADMSPrivilegedRoleAssignment' 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-AzureADMSPrivilegedRoleAssignment
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-AzureADMSPrivilegedRoleAssignment:String) [], CommandNotFoundExcept
   ion
    + FullyQualifiedErrorId : CommandNotFoundException

Any suggestion will be helpful.

Sridevi
  • 10,599
  • 1
  • 4
  • 17
Jim Macaulay
  • 4,709
  • 4
  • 28
  • 53
  • execute the command `Get-Module -Name *AzureAD*`, you only have to have the preview version of AzureAD Module. Also, try `Get-Command Get-AzureADMSPrivilegedRoleAssignment` Share the output of both command – SoySolisCarlos Sep 21 '22 at 18:51

1 Answers1

2

Get-AzureADMSPrivilegedRoleAssignment : The term 'Get-AzureADMSPrivilegedRoleAssignment' is not recognized as the name of a cmdlet, function, script file, or operable program.

This error usually occurs when you don't have AzureADPreview module installed while running that command.

I tried to reproduce the same in my environment and got the same error as below:

Connect-AzureAD -TenantId <your_tenantID>
Get-Module -Name *AzureAD*
Get-AzureADMSPrivilegedRoleAssignment -ProviderId aadRoles -ResourceId <your_tenantID>

Response:

enter image description here

To resolve the error, you need to install AzureADPreview module.

If you try to install that module without removing AzureAD module, you will get error as below:

 Install-Module -Name AzureADPreview

Response: enter image description here

To resolve this, close the existing session and open new PowerShell window by running as Administrator.

Make sure to uninstall AzureAD module and install AzureADPreview module like below:

Uninstall-Module -Name AzureAD
Install-Module -Name AzureADPreview
Import-Module AzureAD
Connect-AzureAD -TenantId <your_tenantID>
Get-Module *AzureAD*

Response: enter image description here

After installing AzureADPreview module, I got the response successfully when I ran below command:

Get-AzureADMSPrivilegedRoleAssignment -ProviderId aadRoles -ResourceId <your_tenantID>

Response:

enter image description here

Sanjeevi Subramani
  • 501
  • 1
  • 5
  • 16
Sridevi
  • 10,599
  • 1
  • 4
  • 17
  • Why install `AzureADPreview` when you have [`AzureAD`](https://learn.microsoft.com/en-us/powershell/module/azuread/?view=azureadps-2.0)? – Rajesh Swarnkar May 06 '23 at 15:07