I have a Powershell form used by support staff to enter required data for a new user account, it then goes away and creates the account, populates attributes and assigns an Office 365 license as required.
I included the option to add users to up to 4 security groups and 4 distribution groups. It all works just fine, however if any of the group memberships are left blank, as in a user is only added to 2 distribution groups, the Powershell window gives errors because of the null values, it still creates the user and adds them to the selected groups so it does not stop anything.
I have added the instruction to hide the powershell window and only display the form itself, but I would like it if I could find a way to tell it to skip the add to groups if the value is blank, my neat freak side is not happy seeing these lines of red code show up even though only I see them and they do not represent an actual problem.
The groups are selected via a dropdown list displayed in a combobox, one combobox per possible group addition and the selected group is used as the value for a variable which the code then uses to add the user to the selected group. Each variable is included in its own line of code which adds the group membership.
So my question is this, is there a way to tell it to skip the add to group operation if no value is selected in the combobox?
We have a traditional AD domain, all DCs are Server 2016 but the functional level is still 2012 R2 thanks to a legacy CRM app that will not work if we raise the domain to 2016, this is being replaced but at this moment we are stuck with 2012 R2. We sync with Azure/Office 365 using AADC. The environment is 80% virtual running in Hyper-V