> Mobilité > Les scripts de sauvegarde et recouvrement pour Exchange

Les scripts de sauvegarde et recouvrement pour Exchange

Mobilité - Par Arnaud Alcabez - Publié le 20 juin 2011
email

Avec l’arrivée de solutions en ligne, je me suis penché sur les problématiques que ce type d’environnement pouvait poser en termes de disponibilité pour le contenu de vos boîtes aux lettres.

Après la préparation du plan de recouvrement dont nous avons parlé la semaine dernière, nous allons voir ici les scripts à utiliser.

Les scripts de sauvegarde et recouvrement pour Exchange

Le script suivant permet de sauvegarder une boîte aux lettres ou l’ensemble des boîtes aux lettres d’une entreprise. Il vous suffit de recopier les instructions suivantes dans un fichier texte que vous renommerez Backup-MSOnlineUserMailbox.ps1. Procédez de même pour le script de restauration.

#
# Microsoft BPOS Script
#
# NAME: Backup-MSOnlineUserMailbox.ps1
#
# AUTHOR: Arnaud Alcabez
# DATE : 19/07/2010
#
# COMMENT: Use this script to backup an online user mailbox
#
#
#
==============================================================================================
cls

# Enlarge the console to display location results
mode con cols=180

# Load the Exchange Transporter Cmdlets if there are not loaded
$ExCmd = $False
$Modules = Get-PSSnapIn
ForEach ($_.Name in $Modules) {if ($_.Name -eq « Microsoft.Exchange.Transporter ») { $ExCmd = $True
}}
If ($ExCmd -eq $False) {Add-PSSnapin Microsoft.Exchange.Transporter}
If ($ExCmd -eq $False) {Write-Host « Note: Exchange Online Cmdlets loaded… »}
Write-Host

Write-Host ‘┌─────────────────────────────────────────────────┐’
-ForegroundColor white -BackgroundColor darkred
Write-Host ‘│ │’ -ForegroundColor white -BackgroundColor darkred
Write-Host ‘│ Enter your Exchange Online Admin ID account │’ -ForegroundColor white
-BackgroundColor darkred
Write-Host ‘│ │’ -ForegroundColor white -BackgroundColor darkred
Write-Host ‘└─────────────────────────────────────────────────┘’
-ForegroundColor white -BackgroundColor darkred
Write-Host

# Get the login ID for the BPOS admin account
$Credlogin = Read-Host ‘Administrator Login ID’
$Credpwd = Read-Host ‘Password’ -AsSecureString
Write-Host

Write-Host

Write-Host ‘┌─────────────────────────────────────────────────┐’
-ForegroundColor white -BackgroundColor darkblue
Write-Host ‘│ │’ -ForegroundColor white -BackgroundColor darkblue
Write-Host ‘│ Backup service for mailbox users on the │’ -ForegroundColor white -BackgroundColor
darkblue
Write-Host ‘│ EMEA Datacenter for Microsoft Online Services │’ -ForegroundColor white
-BackgroundColor darkblue
Write-Host ‘│ │’ -ForegroundColor white -BackgroundColor darkblue
Write-Host ‘└─────────────────────────────────────────────────┘’
-ForegroundColor white -BackgroundColor darkblue
Write-Host

#Enter the usermailbox or (none) to check all mailboxes
$Usrbal = Read-Host ‘Enter the user mailbox to backup or press [Enter] for all mailboxes’
Write-Host

# To automate the script, delete previous lines, modify the variables above, and remove the dash
# $CredLogin = “admin@masociete.com”
# $Credpwd = “Password1”
# $UsrBal = “”

# Form the BPOS encrypted credential information and store it in a variable to be passed to upcoming commands
$Cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList
$Credlogin, $Credpwd

If ($Usrbal -Eq «  »)
{
$balnb=Get-MSOnlineUser -Enabled -Credential $cred
Write-Host ‘*** WARNING *** There are’ $balnb.Count ‘mailboxes to backup’ -ForegroundColor white
-BackgroundColor darkred
Write-Host
$Reponse = Read-Host ‘INFO: The backup of all mailboxes can take several hours. Are you sure? [Y/N]’
Write-Host
If ($Reponse.ToUpper() -ne « Y »)
{
Write-Host « INFO: The command is cancelled by the user »
Write-Host
Break
}
}
If ($Usrbal -Eq «  »)
{
$Colusers = Get-MSOnlineUser -Credential $cred -Enabled -ResultSize 10000
ForEach($User in $Colusers){
Write-Host ‘INFO: Backup of’ $User.Identity
Get-XsHostedExchangeMailboxdata -sourceserver « red002.mail.emea.microsoftonline.com »
-sourcelocation « https://red002.mail.emea.microsoftonline.com/exchange » -sourceidentity $User.Identity
-sourceadmincredential $cred | export-transporterbinary -targetfilepath . -targetfileprefix $User.Identity
}
Write-Host
}

Else {
Write-Host ‘INFO: The backup of’ $usrbal ‘mailbox is starting. (This process can take several minutes).
Please, stand by…’
Get-XsHostedExchangeMailboxdata -sourceserver « red002.mail.emea.microsoftonline.com »
-sourcelocation « https://red002.mail.emea.microsoftonline.com/exchange » -sourceidentity $Usrbal
-sourceadmincredential $cred | export-transporterbinary -targetfilepath . -targetfileprefix $Usrbal
Write-Host ‘INFO: The backup of’ $usrbal ‘is finished.’
Write-Host
}

Téléchargez cette ressource

Préparer l’entreprise aux technologies interconnectées

Préparer l’entreprise aux technologies interconnectées

Avec la « quatrième révolution industrielle », les environnements hyperconnectés entraînent de nouveaux risques en matière de sécurité. Découvrez, dans ce guide Kaspersky, comment faire face à cette nouvelle ère de vulnérabilité.

Mobilité - Par Arnaud Alcabez - Publié le 20 juin 2011