So the SQL scripts C:\Users\serviceamefusn\Desktop\ServerRefresh\DBBak.sql" and ClusterRestore.sql, currently exeuting as mannual method from MS-SQL mgmt studio
Is there way we can do it directly from PowerShell script? so that One click will complete all required steps
If I understand correctly, you are executing the PowerShell
Invoke-Sqlcmd commands from an interactive SSMS PowerShell session on Server1 in the context of the Server2 target database server. Those same commands can be executed directly from any PowerShell session on Server1 but you need to specify the
-Server argument in order to run the SQL scripts against the remote Server2 instance. You should be able to include these in your existing PowerShell script file:.
Invoke-Sqlcmd -InputFile "C:\Users\serviceamefusn\Desktop\ServerRefresh\DBBak.sql" -Server "Server2" | Out-File -filePath "C:\Temp\RestoreLogSqlCmd.rpt" -verbose Invoke-Sqlcmd -InputFile "C:\Users\serviceamefusn\Desktop\ServerRefresh\ClusterRestore.sql" -Server "Server2" | Out-File -filePath "C:\Temp\RestoreClusterLogSqlCmd.rpt" -verbose