Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Powershell SMO job.alter() doesn't update the SQL Steps

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()
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You’re not actually updating the command text, you’re just outputting it.

Try

$steps.Command = $steps.Command -Replace("CurrentStringX", "$NewStringX")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading