# Step 1 - you may need to load the assembly if you do not use
SQLPS
PS SQLSERVER:\sql\XU-ACER-PC\DEFAULT\JobServer\Jobs\>
[reflection.assembly]::loadwithpartialname("microsoft.sqlserver.smo")
#Step 2 - create a job step object
PS SQLSERVER:\sql\XU-ACER-PC\DEFAULT\JobServer\Jobs\>
$js=new-object
microsoft.sqlserver.management.smo.agent.jobstep
#Step 3 - see all of the job steps for
all jobs
PS SQLSERVER:\sql\XU-ACER-PC\DEFAULT\JobServer\Jobs\>
$js=dir
| %{$_.EnumJobStepsByID()}
| ft parent,id,name -auto
PS SQLSERVER:\sql\XU-ACER-PC\DEFAULT\JobServer\Jobs\>
$js
#Step 4 - change the job step properties such as retry
attempts
PS SQLSERVER:\sql\XU-ACER-PC\DEFAULT\JobServer\Jobs\>
$js | %{$_.retryAttempts=5;$_.Alter()}
#Step 5 - What if you just want
to change
the property
for some
jobs(e.g., jobs begin with
P)?
PS SQLSERVER:\sql\XU-ACER-PC\DEFAULT\JobServer\Jobs\>
$js=dir
|? {$_.Name -like "P*"}| %{$_.EnumJobStepsByID()}
| ft parent,id,name -auto #note 1: The filter part is ? {$_. }, not ? %{$_.};
note 2: filtering on the job name,not on job step name
PS SQLSERVER:\sql\XU-ACER-PC\DEFAULT\JobServer\Jobs\>
$js