November 22, 2015 at 3:54 am
Got attached powershell script from
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
November 23, 2015 at 3:16 am
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
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply