Created
April 26, 2017 04:13
-
-
Save bill-long/2f28bbbb0372411c608b37026f8f5a34 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Reset-MailboxSD | |
# | |
# This version is intended for Exchange 2013 and 2016, where we have to | |
# update the value in AD. | |
# | |
# Usage: | |
# | |
# To do one user: | |
# | |
# .\Reset-MailboxSD.ps1 "CN=SomeUser,OU=Wherever,DC=contoso,DC=com" | |
# | |
# To do all mailboxes that start with "Foo": | |
# | |
# Get-Mailbox Foo* | % { .\Reset-MailboxSD.ps1 $_.DistinguishedName } | |
param($dn) | |
$securityDescriptor = New-Object -TypeName System.Security.AccessControl.RawSecurityDescriptor -ArgumentList "O:PSG:PSD:(A;CI;CCRC;;;PS)" | |
$user = [ADSI]("LDAP://" + $dn) | |
$user.Properties["msExchMailboxSecurityDescriptor"].Clear() | |
[byte[]]$mbxSdBytes = [System.Array]::CreateInstance([System.Byte], $securityDescriptor.BinaryLength) | |
$securityDescriptor.GetBinaryForm($mbxSdBytes, 0) | |
$user.Properties["msExchMailboxSecurityDescriptor"].Add($mbxSdBytes) | |
$user.CommitChanges() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment