16 Jun 2011 @ 4:55 PM 

I wrote a Powershell script today that moves a mailbox and then resets its AD permissions (To fix ActiveSync issues after moving from Exchange 2007 to Exchange 2010). Just thought i’d share it.

#© Daniel Stone, 2011 daenks at daenks dawt org
param([string]$Source, [string]$Destination)
if (!$Source) {
Write-Host “Please Specify a Source Store with the -Source parameter”
Exit -1
}
if (!$Destination) {
Write-Host “Please Specify a Destination Store with the -Destination parameter”
Exit -2
}

$i = 0
$ds = New-Object System.DirectoryServices.DirectorySearcher([ADSI]”LDAP://dc=quintanaminerals,dc=com”)
$Moves = Get-Mailbox -Database $Source
foreach ($mailbox in $Moves) {
$i = $i + 1
Write-Host $i
if ($i -eq 14)
{
Write-Host “15 Mailbox Limit Exceeded. Please allow the first 15 moves to complete before starting more.”
Exit -3
}
New-MoveRequest -Identity “$($mailbox.DisplayName)” -TargetDatabase $Destination
$ds.Filter = “(&(objectCategory=person)(objectClass=user)(cn=$($mailbox.DisplayName)))”
$DSResults = $ds.FindAll()
foreach ($item in $DSResults) {
$user = $item.GetDirectoryEntry()
Write-Host “Correcting Permissions for: $($user.sAMAccountName)”
$user.psbase.ObjectSecurity.SetAccessRuleProtection($false,$true)
$user.psbase.CommitChanges()
}
}
#© Daniel Stone, 2011 daenks at daenks dawt org

I realize there are some improvements that i could make, like a LOT more error checking. But this will do for me for now 🙂

Oh yea, and WordPress messed up the indentation, sorry 🙂

Posted By: Daenks
Last Edit: 16 Jun 2011 @ 04:58 PM

EmailPermalink
Tags


 

Responses to this post » (None)

 
Post a Comment

You must be logged in to post a comment.


 Last 50 Posts
Change Theme...
  • Users » 727
  • Posts/Pages » 8
  • Comments » 0
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight

About



    No Child Pages.