Backup a Domain Controler PowerShell Script

Voici un script PowerShell permettant d’automatiser la mise en place d’une sauvegarde via l’outil natif de Microsoft Windows Backup.

Il n’est pas toujours facile de mettre en place une stratégie avec les outils graphiques qui sont pauvres, voice une script pour se faire



write-host "Vérification des prérequis... " `r
import-module servermanager
$BackupFeatures = get-windowsfeature -name Backup-Features
$BackupTools = get-windowsfeature -name Backup-Tools
IF ($BackupFeatures.Installed -eq $False) {
add-windowsfeature Backup-Features
}
Else{
	Write-host "Backup OK... " `r
	}
IF ($BackupTools.Installed -eq $False) {
add-windowsfeature Backup-Tools
}
Else{
	Write-host "Backup OK... " `r
	}

write-host "Configuring the Powershell session for Backup..." `r
$PSSnapInCheck = get-pssnapin | where-object {$_.name -like "*Backup*"}

IF ($PSSnapInCheck -notlike "ServerBackup"){
	add-pssnapin Windows.ServerBackup
}
Write-Host "Backup Volume"
$BackupTargetVolume = "E:"
$BackupTarget = New-WBBackupTarget -VolumePath $BackupTargetVolume
write-host "Creation de la strategie de sauvegarde..." `r
$BackupPolicy = New-WBPolicy
Add-WBBackupTarget –Policy $BackupPolicy –Target $BackupTarget
Add-WBBareMetalRecovery –Policy $BackupPolicy
Set-WBSchedule –Policy $BackupPolicy –Schedule 6:00
Set-WBSchedule –Policy $BackupPolicy –Schedule 18:00
set-WBPolicy –Policy $BackupPolicy
write-host "The Backup Policy is now configured & scheduled..." `r
$BackupPolicy

# Perform the backup
write-host "Backing up System State on $computer" -foregroundcolor Green `r
$Result = Start-WBBackup -Policy $BackupPolicy

Laisser un commentaire