November 10, 2014 at 11:19 am
when I run the script below in ISE it runs fine. when I try to schedule as a job to run it blows up. I get the following error
"get-childitem : Cannot call method. The provider does not support the use of filters."
I have tried scheduling as a CMD type job in SQL and as a powershell type job.
Any ideas??
import-module sqlps -DisableNameChecking
$server = "<servername>"
$DBNAME = "<dbname>"
$path = "<UNC Path to backup location>\$Server\$dbname\"
$lastwritetime = gci $path -Filter *.BAK | Measure-Object -Property lastwritetime -Maximum
$databasefiles = gci $path -Filter *.bak | Where-Object{$_.LastWriteTime -GE $($lastwritetime.Maximum)} | Sort-Object -Property {[int]$_.Name.Split('of')[0]}
## set loop variable
$i = 0
<# counts number of files. if only one .bak file then will execute the following statement
create a string array and initalize
#>
[string[]] $bup = @()
$bup = if($databasefiles.count -eq 1)
{$path + $databasefiles[$i]}
else
{
while($i -lt $databasefiles.length)
{
if ($i -eq $databasefiles.Length -1)
{$path + $databasefiles[$i]}
else
{$path + $databasefiles[$i]}
$i++
}
}
Restore-SqlDatabase -Database <DBName> -ServerInstance <ServerName> -BackupFile $bup -ReplaceDatabase
November 11, 2014 at 2:38 am
Try using -Include in place of -Filter.
Gaz
-- Stop your grinnin' and drop your linen...they're everywhere!!!
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply