Issue
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()
}
Solution
You're not actually updating the command text, you're just outputting it.
Try
$steps.Command = $steps.Command -Replace 'CurrentStringX, $NewStringX
Answered By - squillman Answer Checked By - David Marino (sql.easybugfix Volunteer)
Post a Comment
Post a Comment