Removing PIM approvers from Entra using powershell, code doesnt fail but approvers still present

MrFlinstone 686 Reputation points
2025-06-01T08:18:39.42+00:00

I am currently using powershell to add approvers for PIM settings, however I am trying to remove the approvers using powershell, the code i am using can be found below. For reasons unknown to me, it doesnt appear to work. It doesnt fail, but doesnt make the required change either.

$policyid = "Group_xxx"


$body = @{
    "@odata.type" = "#microsoft.graph.unifiedRoleManagementPolicyApprovalRule"
    id = "Approval_EndUser_Assignment"
    target = @{
        "@odata.type" = "microsoft.graph.unifiedRoleManagementPolicyRuleTarget"
        caller = "EndUser"
        operations = @("All")
        level = "Assignment"
        inheritableSettings = @()
        enforcedSettings = @()
    }
    setting = @{
        "@odata.type" = "microsoft.graph.approvalSettings"
        isApprovalRequired = $false
        isApprovalRequiredForExtension = $false
        isRequestorJustificationRequired = $false
        approvalMode = "SingleStage"
        approvalStages = @(
            @{
                "@odata.type" = "microsoft.graph.unifiedApprovalStage"
                approvalStageTimeOutInDays = 1
                isApproverJustificationRequired = $false
                escalationTimeInMinutes = 0
                primaryApprovers = @()  # Removes all approvers
                isEscalationEnabled = $false
                escalationApprovers = @()
            }
        )
    }
}


Update-MgPolicyRoleManagementPolicyRule `
    -UnifiedRoleManagementPolicyId $policyid `
    -UnifiedRoleManagementPolicyRuleId "Approval_EndUser_Assignment" `
    -Body $body
Microsoft Security | Microsoft Entra | Microsoft Entra ID
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Vigneshwar Duvva 2,300 Reputation points Microsoft External Staff Moderator
    2025-06-03T06:03:00.8+00:00

    Hello @MrFlinstone

    To remove approvers from a PIM role management policy using PowerShell, ensure you're using the correct parameter name (-Body Parameter instead of -Body) and validate the structure of your approval settings. Here's the corrected approach:

    $policyid = "Group_xxx"

    $ruleId = "Approval_EndUser_Assignment"

    $body = @{

    Copy

    "@odata.type" = "#microsoft.graph.unifiedRoleManagementPolicyApprovalRule"

    id = $ruleId

    target = @{

    "@odata.type" = "microsoft.graph.unifiedRoleManagementPolicyRuleTarget"
    
    caller = "EndUser"
    
    operations = @("All")
    
    level = "Assignment"
    
    inheritableSettings = @()
    
    enforcedSettings = @()
    

    }

    setting = @{

    "@odata.type" = "microsoft.graph.approvalSettings"
    
    isApprovalRequired = $false  # Disables approval requirement
    
    isApprovalRequiredForExtension = $false
    
    isRequestorJustificationRequired = $false
    
    approvalMode = "NoApproval"  # Explicitly set approval mode
    
    approvalStages = @()  # Remove all approval stages
    

    }

    }

    Update-MgPolicyRoleManagementPolicyRule -UnifiedRoleManagementPolicyId $policyid -UnifiedRoleManagementPolicyRuleId $ruleId -BodyParameter $body

    Confirm permissions with Connect-MgGraph -Scopes "RoleManagement.ReadWrite.Directory"

    https://learn.microsoft.com/en-us/powershell/microsoftgraph/how-to-manage-pim-policies?view=graph-powershell-1.0

    Check policy rules using:

    PowerShell

    Get-MgPolicyRoleManagementPolicy -UnifiedRoleManagementPolicyId $policyid | Select-Object -ExpandProperty Rules

    Hope this helps.


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.