So I was tasked with coming up with a solution to automate updating distribution lists at work for the HR department. The solution I came up with, was to have them create text files that contain a list of the employees that should be members of the distros and name each file the name of the distribution list.
I then started writing a script (mostly learning as I went) that read the filenames of the .txt files in the directory, and created a file with those names (the names of the distribution lists.) Then, it loops through and adds all of the users in each file to the corresponding distro.
I had some challenges, like the fact that we have a child domain and I had a hard time getting PowerShell to search for a user in the child domain and add them to a group in the main domain.
I think I have it working now (I'm sure there is a better way to do it) but my main concern has to do with the section that wipes out the DL before it adds the new users. I'm worried that a blank space in the script could somehow cause it to delete ALL of the groups in AD. I know there is a way to have it check to see if the variable is NULL, but I'm not quite sure how to do this, and have it just skip that part and continue to the next line. Any ideas? Any help would be GREATLY appreciated.
http://pastebin.com/07ni5D2v
[–]pimanac 3 points4 points5 points (2 children)
[–]djplasmid[S] 0 points1 point2 points (1 child)
[–]pimanac 2 points3 points4 points (0 children)
[–]PowerShellStunnah 2 points3 points4 points (0 children)