Powershell Script to restore DB

  • Got attached powershell script from

    http://www.biztalkadminsblogging.com/index.php/blog-archive/item/107-powershell-script-restoring-biztalk-server-2010-databases

    But its throwing below error for me.. Any Powershell Experts here.

    You cannot call a method on a null-valued expression.

    At C:\MSSQL\MSSQL_QUERIES\BizTalk\Restore.ps1:35 char:252

    + $script:Lastfullback | Add-Member -type NoteProperty -name "FileName" -va

    lue ((Get-ChildItem $FullBackupLocation | Where-Object {$_.name -like "$FullBac

    kupFilePrefix*,"} | sort-object name -descending | select-object -first 1 -expa

    nd name).ToUpper <<<< ())

    + CategoryInfo : InvalidOperation: (ToUpper:String) [], RuntimeEx

    ception

    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.

    At C:\MSSQL\MSSQL_QUERIES\BizTalk\Restore.ps1:36 char:112

    + $script:Lastfullback | Add-Member -type NoteProperty -name "Mark" -value

    ((($Lastfullback.Filename).replace <<<< ("$FullBackupFilePrefix", "")).TrimEnd(

    ".BAK"))

    + CategoryInfo : InvalidOperation: (replace:String) [], RuntimeEx

    ception

    + FullyQualifiedErrorId : InvokeMethodOnNull

    The last full backup file is:

    Found 0 log backup files.

    Cannot index into a null array.

    At C:\MSSQL\MSSQL_QUERIES\BizTalk\Restore.ps1:109 char:62

    + $script:LastLogBackup = $LogFilesSinceLastFullBackup[ <<<< ($LogFiles

    SinceLastFullBackup.Count-1)]

    + CategoryInfo : InvalidOperation: (-1:Int32) [], RuntimeExceptio

    n

    + FullyQualifiedErrorId : NullArray

    NULL

    Finished generating

  • I may not be helping fix this particular problem, but I had a look at the PS and the embedded sql and have difficulty reading it inside the PS.

    How about using the built in backup and restore CmdLet instead of invoking SQL from Powershell?

    This may simplify the script and make it easier to debug.

    Restore-SqlDatabase -ServerInstance MySQL -Database AdventureWorks `-BackupFile

    "\\Myserver\MyShareFolderWithRights\Backup\AdventureWorks12Nov20151012AM.bak"

    -ReplaceDatabase

    Catch-all queries done right [/url]
    Gail Shaw's Performance Blog[/url]

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply