Reputation: 80
Am looking to connect and loop through hundreds of SQL servers/instances, to find a specific job, with a specific job step, and looking to modify the command inside that job step to change a 1 to 0 - and I wish to use PowerShell to do this.
I have a PS script to enable or disable an entire Job, but I don't want to disable the job or even the job step. I want to change the syntax inside the step, eg. from @ENABLED=1 to @ENABLED=0
I need to target these SQL servers by IP address with specific SQL permissions (eg. sa account) as the servers are not on a domain (VMs inside vCloud Director with NAT'ed IPs)
SQL Server 2014 w\SP1 PowerShell v5 Windows Server 2012 R2 & 2008 R2
Thanks in advance Darren
Upvotes: 2
Views: 1588
Reputation: 1623
Using SMO
$newCmd = "DECLARE @ENABLED`nSET @ENABLED = 0`n-- This is the end"
add-type -AssemblyName "Microsoft.SqlServer.Smo, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"
$srvObj = new-object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $connectToThisServer
$srvObj.JobServer.Jobs['testJob3'].JobSteps['secondStep'].Command
$srvObj.JobServer.Jobs['testJob3'].JobSteps['secondStep'].Command = $newCmd
$srvObj.JobServer.Jobs['testJob3'].JobSteps['secondStep'].Alter()
Upvotes: 2