I activated PIM for an eligible group using the command
New-MgIdentityGovernancePrivilegedAccessGroupAssignmentScheduleRequest -BodyParameter
Now, After completing my task I want to exit the role by deactivating this assignment. From the documentation, I figured I could use the below command. But this is not working and is giving me a bad request error.
Stop-MgIdentityGovernancePrivilegedAccessGroupAssignmentScheduleRequest -PrivilegedAccessGroupAssignmentScheduleRequestId
The error occurred as you are using wrong command to deactivate the user assignment from PIM group.
I have one active assignment to group in PIM under Groups
tab as below:
When I ran your command to deactivate the above assignment, I too got same error as below:
Stop-MgIdentityGovernancePrivilegedAccessGroupAssignmentScheduleRequest -PrivilegedAccessGroupAssignmentScheduleRequestId xxxxxx
Response:
To deactivate the active assignment of user from PIM group, you need to use below PowerShell commands with action as selfDeactivate
like this:
Connect-MgGraph -Scope "PrivilegedAssignmentSchedule.ReadWrite.AzureADGroup"
$params = @{
accessId = "member"
principalId = "userId"
groupId = "groupId"
action = "selfDeactivate"
}
New-MgIdentityGovernancePrivilegedAccessGroupAssignmentScheduleRequest -BodyParameter $params
Response:
When I checked the same in Portal, active user assignment deactivated successfully from PIM group as below:
Reference: Create assignmentScheduleRequest - Microsoft Graph