send Windows server 2008 last backup status to a .txt file RRS feed

  • Question

  • I need a script that runs locally on a Windows server 2008 R2 and sends the last backup status (Failure or Success ) to a local .txt file.

    I am using the following script :

    Add-PSSnapin -Name Windows.Serverbackup
    $WBJob=Get-Content env:computername
    $WBResult = $WBSummary.LastBackupResultHR

    Set-Location -Path C:\Scripts
    $OutputFile= (Get-Location).Path +'\output.txt'
    Remove-Item $OutputFile
    If ($WBResult -eq 0) { $WBResult = "Successful"}
    Else { $WBResult = "Failed"}

    $writer=[System.IO.Streamwriter] $OutputFile
    $Writer.WriteLine('Server Name: '+$WBJob+'            Backup Results:'+$WBResult )


    Unfortunately every time I am running this ps1 script the result is always " Failed " even when the last backup status is   Success.

    Server Name: Server-2008            Backup Results:Failed

    What am I doing wrong?I need some help.

    • Edited by Emil Iancu Monday, May 7, 2018 12:24 PM
    Monday, May 7, 2018 12:23 PM

All replies