Exchange et Powershell : duplication de mailbox

Ayant remis un peu les mains sur Exchange, j’ai dû réaliser la création de multiples Equipment Mailbox ; voilà qui était donc une excellente idée de départ pour mon tout premier script Powershell pour Exchange.

Ce script permet donc de dupliquer une mailbox existante vers une autre, en gardant la quasi-totalité de ses propriétés et privilèges accordés. Ensuite, le script gère les paramètres propres aux réservations, mais il est bien évidemment possible de mettre cette portion en commentaire.

Write-Host "Equipment Mailbox Duplication Script"
 Write-Host "====================================`r`n"
 $srcmbxname = Read-Host "Source Equipment Mailbox Name or Alias"
 $srcmbx = Get-Mailbox $srcmbxname -ErrorAction Stop
 $srccal = Get-CalendarProcessing $srcmbxname -ErrorAction Stop
 $srcperm = Get-MailboxPermission $srcmbxname
 $newmbxname = Read-Host "New Equipment Mailbox Name"
 $newmbxalias = Read-Host "New Equipment Mailbox Alias"
 $newmbxaddr = Read-Host "New Equipment Mailbox Address"
 Write-Host "Creating the new mailbox…"
 New-Mailbox -Name $newmbxname -Alias $newmbxalias -UserPrincipalName $newmbxaddr -SamAccountName $newmbxalias -OrganizationalUnit $srcmbx.OrganizationalUnit -Equipment -ErrorAction Stop
 Write-Host "Copying basic mailbox properties."
 Set-Mailbox $newmbxalias -UseDatabaseRetentionDefaults $srcmbx.UseDatabaseRetentionDefaults -RetainDeletedItemsUntilBackup $srcmbx.RetainDeletedItemsUntilBackup -GrantSendOnBehalfTo $srcmbx.GrantSendOnBehalfTo -DeliverToMailboxAndForward $srcmbx.DeliverToMailboxAndForward -LitigationHoldEnabled $srcmbx.LitigationHoldEnabled -SingleItemRecoveryEnabled $srcmbx.SingleItemRecoveryEnabled -RetentionHoldEnabled $srcmbx.RetentionHoldEnabled -CalendarRepairDisabled $srcmbx.CalendarRepairDisabled -MessageTrackingReadStatusEnabled $srcmbx.MessageTrackingReadStatusEnabled -RetainDeletedItemsFor $srcmbx.RetainDeletedItemsFor -RecipientLimits $srcmbx.RecipientLimits -AntispamBypassEnabled $srcmbx.AntispamBypassEnabled -CalendarVersionStoreDisabled $srcmbx.CalendarVersionStoreDisabled -HiddenFromAddressListsEnabled $srcmbx.HiddenFromAddressListsEnabled -MaxSendSize $srcmbx.MaxSendSize -MaxReceiveSize $srcmbx.MaxReceiveSize -EmailAddressPolicyEnabled $srcmbx.EmailAddressPolicyEnabled -RequireSenderAuthenticationEnabled $srcmbx.RequireSenderAuthenticationEnabled -SendModerationNotifications $srcmbx.SendModerationNotifications -ExternalOofOptions $srcmbx.ExternalOofOptions -ProhibitSendQuota $srcmbx.ProhibitSendQuota -ProhibitSendReceiveQuota $srcmbx.ProhibitSendReceiveQuota -DowngradeHighPriorityMessagesEnabled $srcmbx.DowngradeHighPriorityMessagesEnabled -UseDatabaseQuotaDefaults $srcmbx.UseDatabaseQuotaDefaults -IssueWarningQuota $srcmbx.IssueWarningQuota -RemoteRecipientType $srcmbx.RemoteRecipientType -AuditEnabled $srcmbx.AuditEnabled -AuditLogAgeLimit $srcmbx.AuditLogAgeLimit -AuditAdmin $srcmbx.AuditAdmin -AuditDelegate $srcmbx.AuditDelegate -AuditOwner $srcmbx.AuditOwner -AcceptMessagesOnlyFromDLMembers $srcmbx.AcceptMessagesOnlyFromDLMembers -ArbitrationMailbox $srcmbx.ArbitrationMailbox -BypassModerationFromSendersOrMembers $srcmbx.BypassModerationFromSendersOrMembers -CustomAttribute1 $srcmbx.CustomAttribute1 -CustomAttribute2 $srcmbx.CustomAttribute2 -CustomAttribute3 $srcmbx.CustomAttribute3 -CustomAttribute4 $srcmbx.CustomAttribute4 -CustomAttribute5 $srcmbx.CustomAttribute5 -CustomAttribute6 $srcmbx.CustomAttribute6 -CustomAttribute7 $srcmbx.CustomAttribute7 -CustomAttribute8 $srcmbx.CustomAttribute8 -CustomAttribute9 $srcmbx.CustomAttribute9 -CustomAttribute10 $srcmbx.CustomAttribute10 -CustomAttribute11 $srcmbx.CustomAttribute11 -CustomAttribute12 $srcmbx.CustomAttribute12 -CustomAttribute13 $srcmbx.CustomAttribute13 -CustomAttribute14 $srcmbx.CustomAttribute14 -CustomAttribute15 $srcmbx.CustomAttribute15 -ExtensionCustomAttribute1 $srcmbx.ExtensionCustomAttribute1 -ExtensionCustomAttribute2 $srcmbx.ExtensionCustomAttribute2 -ExtensionCustomAttribute3 $srcmbx.ExtensionCustomAttribute3 -ExtensionCustomAttribute4 $srcmbx.ExtensionCustomAttribute4 -ExtensionCustomAttribute5 $srcmbx.ExtensionCustomAttribute5 -ModeratedBy $srcmbx.ModeratedBy -ModerationEnabled $srcmbx.ModerationEnabled -RejectMessagesFromDLMembers $srcmbx.RejectMessagesFromDLMembers -SimpleDisplayName $srcmbx.SimpleDisplayName -MailTip $srcmbx.MailTip -MailTipTranslations $srcmbx.MailTipTranslations -ErrorAction Stop
 Write-Host "Done. Now copying calendar processing properties."
 Set-CalendarProcessing -Identity $newmbxalias -AutomateProcessing $srccal.AutomateProcessing -AllowConflicts $srccal.AllowConflicts -BookingWindowInDays $srccal.BookingWindowInDays -MaximumDurationInMinutes $srccal.MaximumDurationInMinutes -AllowRecurringMeetings $srccal.AllowRecurringMeetings -EnforceSchedulingHorizon $srccal.EnforceSchedulingHorizon -ScheduleOnlyDuringWorkHours $srccal.ScheduleOnlyDuringWorkHours -ConflictPercentageAllowed $srccal.ConflictPercentageAllowed -MaximumConflictInstances $srccal.MaximumConflictInstances -ForwardRequestsToDelegates $srccal.ForwardRequestsToDelegates -DeleteAttachments $srccal.DeleteAttachments -DeleteComments $srccal.DeleteComments -RemovePrivateProperty $srccal.RemovePrivateProperty -DeleteSubject $srccal.DeleteSubject -AddOrganizerToSubject $srccal.AddOrganizerToSubject -DeleteNonCalendarItems $srccal.DeleteNonCalendarItems -TentativePendingApproval $srccal.TentativePendingApproval -EnableResponseDetails $srccal.EnableResponseDetails -OrganizerInfo $srccal.OrganizerInfo -ResourceDelegates $srccal.ResourceDelegates -RequestOutOfPolicy $srccal.RequestOutOfPolicy -AllRequestOutOfPolicy $srccal.AllRequestOutOfPolicy -BookInPolicy $srccal.BookInPolicy -AllBookInPolicy $srccal.AllBookInPolicy -RequestInPolicy $srccal.RequestInPolicy -AllRequestInPolicy $srccal.AllRequestInPolicy -AddAdditionalResponse $srccal.AddAdditionalResponse -AdditionalResponse $srccal.AdditionalResponse -RemoveOldMeetingMessages $srccal.RemoveOldMeetingMessages -AddNewRequestsTentatively $srccal.AddNewRequestsTentatively -ProcessExternalMeetingMessages $srccal.ProcessExternalMeetingMessages -RemoveForwardedMeetingNotifications $srccal.RemoveForwardedMeetingNotifications -ErrorAction Stop
 Write-Host "Done. Now setting up permissions."
 foreach($perm in $srcperm){
     if($perm.Deny.IsPresent -eq $false) { Add-MailboxPermission -Identity $newmbxalias -User $perm.User -AccessRights $perm.AccessRights }
     else { Add-MailboxPermission -Identity $newmbxalias -User $perm.User -AccessRights $perm.AccessRights -Deny }
 }
 Write-Host "All done. Successfully created mailbox"$newmbxalias

Le script est téléchargeable dans une version commentée.

Lien pour marque-pages : Permaliens.

Laisser un commentaire

Ce site utilise Akismet pour réduire les indésirables. En savoir plus sur comment les données de vos commentaires sont utilisées.