Hi, I've fairly new to scripting with Powershell but I'm working my way through it. I'm currently working on a script that I have close to working I'm just stuck on one part. I want to take a 3 column csv set up like:
Machine Name Machine Type Groups
Machine1 Desktop group1;group2;group3
Machine2 Laptop group1;group2;group3
The purpose of the script is to create a new machine using the name from column 1 in the correct OU based on the type in column 2 and then add the groups from column 3 to that machine.
So far I have the first two steps working perfectly, it will create the new machine using the correct machine name and place it into the correct OU. If the machine name already exists it kicks it out to an error log so I can go back and investigate.
The adding groups part I almost have working except I get stuck at one part. This may not be the correct or most effcient way of doing it but currently I have it set up to take the list of groups, write to a text file delimited by the semi colon which at that point the txt file looks like:
Group1
Group2
Group3
after adding the groups it deletes the txt file.
This process works great if AD is able to find all the groups names. Unfortunately, long story short with the way I get the csv the group names may not all be correct.
Like the machine names I have it setup that if it runs across a group it cannot add it kicks it out to the error log using try and catch.
Here's where I'm stuck if it comes across 1 group that cannot be added it flows through correctly. It sends it to the error log and then tries to add the next group. However if it then runs into a second group it cannot add it will add it to the error butthen stop and move on to the next MACHINE in the list. It will not try to add any more groups after the second bad one.
So if I had If I had a list that looked like
Good Group 1
Good Group 2
Bad Group 1
Good Group 3
Bad Group 2
Good Good 4
It would make it past Bad group 1 and add good group 3 however once it hits bad group 2 it stops and moves onto the next machine and never tries to add good group 4.
I don't know if its possible to offer any help with this without posting the actual code. I can do that if its needed. The only reason I didn't is with all the trial and error trying to get it work its a bit of mess at this point, please let me know if it would help.
Thank you in advanced for any help.