I have multiple scheduled jobs running in server. All i want is to change the credentials for all scheduled jobs using powershell.
The below is used to list the scheduled jobs in the machine. Now how can i change the credentials for all these jobs. How to use the Set-ScheduledJob
command ?
# PowerShell script to get scheduled tasks from local computer
$schedule = New-Object -ComObject Schedule.Service
$schedule.Connect()
$tasks = $schedule.GetFolder(".").GetTasks(0)
$tasks | Format-Table Name
Thankfully, PowerShell now has options for doing this with less hassle than having a separate script.
$NewTaskCreds = Get-Credential
Get-ScheduledTask | Set-ScheduledTask -User $NewTaskCreds.UserName -Password $NewTaskCreds.GetNetworkCredentials().Password
Of course, that will update EVERY scheduled task, so if you're just updating the password for a specific user, I suggest this:
$NewTaskCreds = Get-Credential
Get-ScheduledTask | Where-Object { $_.Principal.UserId -eq $NewTaskCreds.UserName } | Set-ScheduledTask -User $NewTaskCreds.UserName -Password $NewTaskCreds.GetNetworkCredentials().Password
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With