Reputation: 3
I am working to update the agent job with data based on certain string found under job step. I can see the SMO finding the string displaying the replacement object in memory. But when I try to alter the final output
$AgentJob = Get-SqlAgentjob -ServerInstance $InstanceName | where Name -Like "somestring*"
it doesn't work in updating the actual agent job steps.
Foreach ($steps in $AgentJob.jobsteps)
{
$steps.Command -Replace("CurrentString1","$NewString2")
$steps.Alter()
$steps.Command -Replace("CurrentString2","$NewString2")
$steps.Alter()
$steps.Command -Replace("CurrentString3","$NewString3")
$steps.Alter()
}
Upvotes: 0
Views: 84
Reputation: 13641
You're not actually updating the command text, you're just outputting it.
Try
$steps.Command = $steps.Command -Replace 'CurrentStringX, $NewStringX
Upvotes: 2