Simplify user tasks like bulk creation, updates, password resets, deletions, license checks & more — all from one place.
🚀 Launch ToolkitManaging directory roles effectively is critical to maintaining security and governance in Microsoft 365 and Azure Active Directory. Whether you're removing users, groups, or applications from privileged roles, the Remove-MgDirectoryRoleMemberByRef cmdlet offers a secure and automated way to do it.
In this blog, we’ll explore what this cmdlet does, why it’s essential, and walk through practical examples to help you remove role assignments with confidence.
Remove-MgDirectoryRoleMemberByRef is a Microsoft Graph PowerShell cmdlet used to remove a member (user, group, or service principal) from an activated directory role in Azure Active Directory.
This cmdlet doesn’t delete users or roles—it simply removes the relationship between the directory role and the assigned member. Think of it as revoking access to the permissions tied to that role.
Here’s why this cmdlet is a must-have in any admin’s toolbox:
Remove-MgDirectoryRoleMemberByRef -DirectoryRoleId <String> -DirectoryObjectId <String>
Parameters:
Let’s look at three real-world examples where you might use this cmdlet.
$roleId = (Get-MgDirectoryRole -Filter "displayName eq 'Company Administrator'").Id
$userId = (Get-MgUser -UserId "alex.williams@contoso.com").Id
Remove-MgDirectoryRoleMemberByRef -DirectoryRoleId $roleId -DirectoryObjectId $userId
This removes the user alex.williams@contoso.com from the Global Administrator role.
$customRole = Get-MgDirectoryRole -Filter "displayName eq 'App Manager'"
$sp = Get-MgServicePrincipal -Filter "displayName eq 'CustomApp1'"
Remove-MgDirectoryRoleMemberByRef -DirectoryRoleId $customRole.Id -DirectoryObjectId $sp.Id
Use this when revoking application-level permissions assigned via a custom directory role.
$roleId = (Get-MgDirectoryRole -Filter "displayName eq 'User Administrator'").Id
$groupId = (Get-MgGroup -Filter "displayName eq 'HR Admins'").Id
Remove-MgDirectoryRoleMemberByRef -DirectoryRoleId $roleId -DirectoryObjectId $groupId
Perfect for managing group-based access control, especially in enterprise environments.
No. It only removes the link between a directory role and its member. No data or identities are deleted.
Get-MgDirectoryRoleMember -DirectoryRoleId
Yes, as long as the guest user is a member of the role and you have their object ID.
Here are some practical scenarios where this cmdlet shines:
The Remove-MgDirectoryRoleMemberByRef cmdlet offers a simple, scriptable, and secure way to revoke directory role access in Microsoft 365 and Azure AD. Whether you're managing users, apps, or groups, it's an essential tool in your admin toolkit.
Want to streamline your role assignment and revocation processes? Stay tuned for our upcoming scripts and automation playbooks tailored for IT admins!
Did You Know? Managing Microsoft 365 applications is even easier with automation. Try our Graph PowerShell scripts to automate tasks like generating reports, cleaning up inactive Teams, or assigning licenses efficiently.
Ready to get the most out of Microsoft 365 tools? Explore our free Microsoft 365 administration tools to simplify your administrative tasks and boost productivity.
© Your Site Name. All Rights Reserved. Design by HTML Codex