# find the jobs owned by the login 'sa'
PS SQLSERVER:\sql\xu_xps\sql2008\jobserver\jobs>
gci |
? {$_.OwnerLoginName -eq
'sa'} |ft name,OwnerLoginName
-autosize
# change the job owner to xu_xps\charlie
PS SQLSERVER:\sql\xu_xps\sql2008\jobserver\jobs>
gci |
? {$_.OwnerLoginName -eq
'sa'} |% {$_.Set_OwnerLoginName("xu_xps\charlie")}
# Verify the jobs have new owners
PS SQLSERVER:\sql\xu_xps\sql2008\jobserver\jobs>
gci |
? {$_.OwnerLoginName -eq
'sa'} |ft name,OwnerLoginName
-autosize
#The change is only in the current session. You have to call
two additional methods to make the change permenent on the server
PS SQLSERVER:\sql\xu_xps\sql2008\jobserver\jobs>
gci |
% {$_.alter()}
PS SQLSERVER:\sql\xu_xps\sql2008\jobserver\jobs>
gci |
% {$_.refresh()}
# After that, you can verify that in SQL Server Agent
# We can do them all in one line
PS SQLSERVER:\sql\xu_xps\sql2008\jobserver\jobs>
gci |
? {$_.OwnerLoginName -eq
'sa'} |% {$_.Set_OwnerLoginName("xu_xps\charlie");$_.alter();$_.refresh()}