I have been busy with using Powershell in these past few days.
I would like to share with you two of the scripts that I used lately. They were both used because of a password change that was made on a service account.
Now the thing about service accounts in Windows 2003 is, they are good, they need elevated privileges in some cases, and since the account is used for the specific purpose then you know that you have to change it once in a while and you know where. Problem is though unless you catch them all – and someone – somewhere did not update the password somewhere, then you will start having issues with account lockouts.
First is to get all the services from all the computers in my OU, and change the password
Line 5 – get all the computers in the desired OU and get the services.
Line 22 – Here is a wait statement for the service to stop, otherwise this will cause issues with the rest of script. Please remember that the time span is there to ensure that if something goes wrong – then you script will continue, otherwise you will have to close the shell window - Ctrl+C will not work.
Line 28 – logs the results to a file including a time stamp.
Second script was to change the passwords for all the scheduled tasks using this same service account
Line 9 – schtasks.exe is the was I decided to go to get the info – I could not find anything else in Powershell that would extract the info.
Line 18-19 – the output came back with an extra “\” in the beginning – I used the Trimstart method to remove it.
Line 25 – This actually took a while to find the exact syntax that I was looking for.
If you have any comments or improvements I would appreciate you input.