This is my script. I am trying to restore a sql backup over to another database. When i run this. This tried to override the original database even though i am specifying a new database. See my script below:
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SqlServer.SMO”) | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SqlServer.SmoExtended”) | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SqlServer.ConnectionInfo”) | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SqlServer.SmoEnum”) | Out-Null
$File =gci c:\sqlbackups -include cstest.bak -Recurse
$CrockfordFile = gci c:\sqlbackups -include cstest.bak -Recurse
copy-Item $file -Destination C:\Webpub\Crockford
Import-Module SQLPS -DisableNameChecking
$svr = New-Object (“Microsoft.SqlServer.Management.Smo.Server”) “SUPPORTPC14\SQLEXPRESS”;
{
$svr.KillAllProcesses(“cstest”)
$svr.KillDatabase(“cstest”)
}
Restore-SqlDatabase -Serverinstance “SUPPORTPC14\SQLEXPRESS” -database “CSTest” -BackupFile $CrockfordFile -ReplaceDatabase