Skip to content

Instantly share code, notes, and snippets.

@bill-long
Created April 26, 2017 04:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bill-long/2f28bbbb0372411c608b37026f8f5a34 to your computer and use it in GitHub Desktop.
Save bill-long/2f28bbbb0372411c608b37026f8f5a34 to your computer and use it in GitHub Desktop.
# 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