Remove-AzureADOAuth2PermissionGrant : Error occurred while executing RemoveOAuth2PermissionGrant

File this one under stupid error messages.

When you want to remove admin consented permissions, Azure AD portal gives the following script:

I was using that to remove a single permission by doing:

This kept throwing the following misleading error:

Turns out the issue is not that the filter is invalid. There was a typo in the ObjectId, so if anything it wasn’t finding anything. Fixed the typo and the cmdlet works again!