Created
August 3, 2016 14:05
-
-
Save davops/2b35e4f970b139334d0afb961c167b0c to your computer and use it in GitHub Desktop.
Revisions
-
davops created this gist
Aug 3, 2016 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ $serverName = "SQL1" ###name of the SQL instance, not the server name $jobQuery = "select jobs.name from msdb.dbo.sysjobs jobs (nolock) join msdb.dbo.syscategories categories (nolock) on jobs.category_id = categories.category_id where jobs.name like '$servername-YourReplicationName%' AND categories.name = 'REPL-Merge'"###Used for merge replication but can be changed $jobQuery = (Invoke-Sqlcmd -ServerInstance $serverName -Query $jobQuery | Select-Object -Property name).name $jobQuery | Out-File c:\logs\database\replication__sync_log.txt -Append foreach ($row in $jobQuery) { Write-Host "The script will start syncrhonization for $row. Is this correct?." $answer = (Read-Host -Prompt "Press 1 to continue. Press 2 to exit.").Trim() if($answer -eq "1"){ $query = "USE msdb EXEC dbo.sp_start_job N'" + $row + "'" Invoke-Sqlcmd -ServerInstance $serverName -Query $query } else{exit} }