Pagine

During Server management it could be useful utilize a powershell script for automatically backing up Server System State on remote Network Share .VHDx.

Here are the step done:

1. Mount remote Share
2. Windows Backup Registry System State
3. Verify
4. Email send for check
5. Unmount network share.

Original Article it's:

http://blogs.sysadmin.it/robimassa/archive/2013/10/07/windows-server-2012-backup-del-systemstate-tramite-powershell.aspx

Here's the relative script:

function SendMail ($a)
{


     $smtpServer = "1.2.3.4"
        
     $MailMessage = new-object Net.Mail.MailMessage

     $smtp = new-object Net.Mail.SmtpClient($smtpServer)

     $MailMessage.From =
mittente@dominio.it
     $MailMessage.ReplyTo =
mittente@dominio.it
     $MailMessage.To.Add(
destinatario1@dominio.it,destinatario2@dominio.it)
     $MailMessage.subject = "Backup SystemState"
     $MailMessage.body = $a

     $smtp.Send($MailMessage)
 
}

Mount-DiskImage
\\SRV01\backup\systemstate\srv02.vhdx

wbadmin start systemstatebackup -backupTarget:z: -quiet

disMount-DiskImage
\\SRV01\backup\systemstate\srv02.vhdx
if ($LastExitCode -eq "0" ) {
    $CorpoMail = "Backup systemstate eseguito correttamente "
    SendMail $CorpoMail
    }
else {
    $CorpoMail = "Backup systemstate eseguito con errori controllare "
    SendMail $CorpoMail
    exit
    }