New to powershell and scripting but have been learning as I go and now have task to perform at work to update AD info for all users. Is working on test box as I'd hoped but want to neaten it up in two ways if possible and running into brick walls. Any help or advice welcome! 🙂

1. Want to add a line to bottom of setad*.txt that I output catch error that says "This many accounts were not found (x)" and have function that counts x

2. Repeat the above for the try section and have '{0} has been updated in AD' -f $user.SamAccountName and pipe to same text file as above also with text of count.

Anyway, it looks like you know the code to use – what's this not doing that you'd like it to do?

by Loomer at 2012-11-20 18:30:26

On steep learning curve. Only halfway through your book 🙂

I was asked by boss if there was a way to go through all of AD and update peoples details so had 3 line code which just imported CSV then cycled through doing Set-ADUser. Worked fine except threw error for user not found on my test system as only loaded a couple of examples.

Boss is a coder but not PS and wanted me to put in Try/Catch with screen output and write to file for user not found. Had to ask around for info especially stuff like [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException] for the catch and advice I got from PS IRC to output to screen and file was code I used as worked. I think I was trying to use Tee-Object but that wouldn't append and -append only available in v3? and needs to be run on v2.

Wanted to add User added on screen and sent to same text file in the try block and also add counter and some text in text file saying how many of success and fail but flailing.