PoshCode Archive  Artifact [08a0a1f003]

Artifact 08a0a1f003f697d2b044f7f0300c5da960683d2ff3ad1aa6910f770b0a50d99e:

  • File Move-Mailbox-2010.ps1 — part of check-in [42e7189f23] at 2018-06-10 13:27:51 on branch trunk — This script is called from a scheduled task running under an account with the recipient role. Gets identities from a distribution group in AD, here named xc2010move but it can be anything you like. This way anyone with permissions to add users to this group can initialize a migration and with the right permissions users can even add themselves to this group (add\remove Self as member). (user: chriskenis size: 2371)

# encoding: utf-8
# api: powershell
# title: Move-Mailbox 2010
# description: This script is called from a scheduled task running under an account with the recipient role. Gets identities from a distribution group in AD, here named xc2010move but it can be anything you like. This way anyone with permissions to add users to this group can initialize a migration and with the right permissions users can even add themselves to this group (add\remove Self as member).
# version: 0.1
# type: script
# author: chriskenis
# license: CC0
# x-poshcode-id: 3577
# x-archived: 2012-08-17T15:12:04
# x-published: 2012-08-13T06:50:00
#
# (changed order of commands to remove users from DG and removed erroneous bracket slipped in while copying code, removed superfluous Identity parameter)
#
param(
#distribution group holding usermailbox(es)
[string] $DistGroup = "XC2010Move",
#move requests per batch/script run
[int] $BatchCount = 5
)

#remove user(s) without mailbox
Get-DistributionGroupMember $DistGroup  | get-user -Filter {Recipienttype -eq "User"} -EA SilentlyContinue | Remove-DistributionGroupMember -Identity $DistGroup -Confirm:$False
#set quotas on moved mailbox(es) and then remove from group
Get-DistributionGroupMember $DistGroup | Get-Mailbox -RecipientTypeDetails "UserMailbox" -EA SilentlyContinue | Where {($_.MailboxMoveStatus -eq ‘Completed’)} | Set-Mailbox -IssueWarningQuota "1920MB" -ProhibitSendQuota "1984MB" -ProhibitSendReceiveQuota "2048MB"
Get-DistributionGroupMember $DistGroup | Get-Mailbox -EA SilentlyContinue -RecipientTypeDetails "UserMailbox" | Remove-DistributionGroupMember -Identity $DistGroup -Confirm:$False
#remove move request(s) upon completion
Get-MoveRequest -MoveStatus Completed | Remove-MoveRequest -Confirm:$False
#get pre-2010 mailbox(es) not yet moved
$MB2Move = Get-DistributionGroupMember $DistGroup | Get-Mailbox -EA SilentlyContinue | Where {($_.RecipientTypeDetails -eq "LegacyMailbox") -and ($_.MailboxMoveStatus -eq ‘None’) -and ($_.ExchangeUserAccountControl -ne "AccountDisabled")} | Get-Random -Count $BatchCount
#create batch label as reference
$batch = "$($env:computername)_MoveMB_{0:ddMMM_yyyy}" -f (Get-Date)
#move pre-2010 mailbox(es)
ForEach ($SingleMailbox in $MB2Move) {New-MoveRequest –Identity $SingleMailbox -BadItemLimit 100 -AcceptLargeDataLoss -Batchname $batch}