I am trying to change passwords for schedule tasks using a powershell script as shown below. The script works fine but every time we change the passwords we will have to go edit the script to add the new password for all these 5 tasks manually I am trying to find if there is a way to do supply the password only once at a prompt and then it will go in and change the password for all tasks on all servers without me entering the passwords manually in the script as is the case now also don't want to store the password in the script.Appreciate your help!
$serverList=get-content D:LOC1LOCserver.txt
foreach ($server in $serverList)
{
Write-Host $server
schtasks /Change /s $Server /RU username /RP 'New_password' /TN "Task1"
schtasks /Change /s $Server /RU username /RP 'New_password' /TN "Task2"
schtasks /Change /s $Server /RU username /RP 'New_password' /TN "Task3"
schtasks /Change /s $Server /RU username /RP 'New_password' /TN "Task4"
schtasks /Change /s $Server /RU username /RP 'New_password' /TN "Task5"
}