I have created a Powershell "app" to make new user creation follow a standard, as in ensure all required attributes have data entered.
As part of this I have added some combo boxes to remind the person creating the account to add new users to security and distribution groups.
Some accounts do not require more than a single security and distribution group, so when the account is created via the "app" (it's a GUI with text entry boxes, combo boxes represented by drop down lists and buttons to execute the account creation process) it spits out a series of errors in the Powershell window because it is trying to add the new account to groups, but the combo box is empty so it can't do what it is being told.
So, my question is, how do I tell it to ignore the instruction to add the new account to a group if the combo box is empty?
The code I'm using, same code for each group apart from the -Identity value.
Add-ADGroupMember -Identity $Securitygroup4dropdown.Text -Members $saMAccountNameentry.Text -confirm:$false
The whole thing is over 2000 lines long, most of it being the GUI, so I am not going to post the whole script here, but to give a little more info
$saMAccountNameentry.Text is a free text entry box used to create the saMAccountName, it is also used to construct the UPN and email address
$Securitygroup4dropdown.Text is one of a series of combo boxes that shows a list of all security groups, the top line of this is blank so unless an entry is selected it has a null value, it's this null value the script doesn't like and causes it to throw the errors.
The errors do not stop the account being created but I don't like seeing the errors. I know I can tell it to hide the Powershell window but that's covering up the errors rather than removing them...