I have created a form for helpdesk staff using Sapien PowerShell Studio, the form is used to create new user accounts. As part of this I have included 4 combo boxes listing all the security groups and 4 more listing all our distribution groups.
The form works, accounts are created and logic to add users to various default groups based on other criteria works as intended.
However, if an account is not being added to 4 groups it gives an error, it still creates the account but it tells me
Add-ADGroupMember : Cannot find an object with identity: '' under: 'DC=xxx,DC=xxxxxxxxxxx,DC=com'.
So it's saying it can't find a group with a blank name, and it does this for each blank combobox, so if a user is being added to 1 security group and nothing else it gives 7 of these errors
As I said, this doesn't stop anything, but just for the sake of my OCD I want it to skip the step if no group is selected from the combobox.
The code used to add the new account to a group is
Add-ADGroupMember -Identity $NewUserSecurityGroupsComboBox1.Text -Members $NewUserIDEntryBox.Text -confirm:$false
I have tried using if statements but no matter how I try to add this it just creates a new error and stops the script.
How can I tell this to use a $null value if the combobox selection is blank?
I can't paste the entire script in here, it is several thousand lines long (most of this is the code for the GUI) and includes images and recovery data