Share via

Client Access Rule syntax

Alistair Russell 61 Reputation points
2020-12-02T10:10:55.68+00:00

Hi

Looking to block access to Exchange Online PowerShell via a client access rule for all users with exception of IT staff and need to be cautious to not lock everyone out of the tenant. Can anyone advise if the below syntax looks right to block all users with exception of specific accounts. This is cloud only, no hybrid:

New-ClientAccessRule -Name "Deny Access to RemotePowerShell" -Action DenyAccess -AnyOfProtocols RemotePowerShell -Enabled $true -UsernameMatchesAnyOfPatterns * -ExceptUsernameMatchesAnyOfPatterns *user1,*user2 -Priority 8 -Scope Users

Thanks in advance

Exchange Online
Exchange Online

A cloud-based service included in Microsoft 365, delivering scalable messaging and collaboration features with simplified management and automatic updates.

0 comments No comments

Answer accepted by question author

Vasil Michev 127K Reputation points MVP Volunteer Moderator
2020-12-02T11:15:07.81+00:00

You can use the Test-ClientAccessRule to check this. As a best practice, you should add a default "allow Remote PowerShell" rule and scope it to at least few users.

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Alistair Russell 61 Reputation points
    2020-12-02T11:17:51.92+00:00

    Thank you Michev. The plan was to create an allow rule with priority 1 to allow access to 2 IT staff and then create the deny rule.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.