@Rich Matheisen :
Thank You very much for helping me with this Code. Just to gain a better understanding, you have used try & catch block.
1# Try will run for every identity every time & in case there is an error encountered then only catch will be executed once?
2# Let's say if I input 100 samaccountnames & then there is either an error with 1 account (at line 50) between will the script terminate at 50 or will continue to complete the operation for the rest of the samaccountnames after 51?
3# Also "-ErrorAction Stop" has been used twice so that in the first case if the samaccountname is inexistant then it writes the error. Second time it is used again so that incase there is an error while updating the attribute then it records that error too.
4# Can it also catch the errors realtime instead of me defining the errors in the blocks?
5# Where does it writes the log file output?Where can I define and how.