I am writing a script, to keep SQL Agent jobs in sync, in an Availability Group in SQL Server. When I find a job that has different step names, I try to update the names on the secondary servers to keep up with changes in the Primary jobs. Here is the snippet where I try to rename the secondary job step:
Where $sJobStep is the secondary job and $pJobStep is from the Primary job.
Here is the error I am getting:
SECONDARY JobStep Name is: step 5
Exception calling “Rename” with “1” argument(s): "Rename failed for JobStep 'step
At I:\Scripts\Sync Job Steps - V9.ps1:138 char:49
CategoryInfo : NotSpecified: ( , MethodInvocationException
FullyQualifiedErrorId : FailedOperationException
I have tried researching the JobStep.Rename function, but I can’t find any help with this error. Can someone point me in the right direction?