Help solve the problem:
I need to periodically restore several MS SQL databases to a test server. I wrote a small script, but after its execution the task does not close and hangs in the "working" state. What's wrong about the script?
Code: Select all
Add-PSSnapin -Name VeeamPSSnapIn
$source_host = "SQL_Main"
$base1 = "base1"
$User = "XXXX\XXXXX"
$PWord = ConvertTo-SecureString -String "XXXXXXXX" -AsPlainText -Force
$target_cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord
$target_host = "SQL_Copy"
$target_instance = "COPY"
$(
$restorepoint = Get-VBRApplicationRestorePoint -SQL -Name $source_host | Sort-Object –Property CreationTime -Descending | Select -First 1
Start-VESQLRestoreSession -RestorePoint $restorepoint
$session = Get-VESQLRestoreSession
$database = Get-VESQLDatabase -Session $session[0] -Name $base1
$restore_session = Restore-VESQLDatabase -Database $database -ServerName $target_host -InstanceName $target_instance -DatabaseName $base1 -GuestCredentials $target_cred -SqlCredentials $target_cred -Force
) *>&1 >> "C:\Errors.log"