Answers

My solution is always to test for nulls, and only attempt to update if there is a value. The only other option is to use a Try/Catch, in which case the command is skipped. With New-ADUser that means the user is not created.

Testing for nulls can mean a series of If statements, with many different New-ADUser statements. Sometimes it is best to create the user with mandatory attributes, then use Set-ADUser for other attributes.

All replies

My solution is always to test for nulls, and only attempt to update if there is a value. The only other option is to use a Try/Catch, in which case the command is skipped. With New-ADUser that means the user is not created.

Testing for nulls can mean a series of If statements, with many different New-ADUser statements. Sometimes it is best to create the user with mandatory attributes, then use Set-ADUser for other attributes.

Actually, the -OtherAttributes parameter takes a hash table. Set up the hash table. If a value exists, add the (attribute, value) pair to the hash table. At the end, if the hash table has at least one entry, a single New-ADUser statement can assign all
of the attributes in the hash table. I have done similar with Set-ADUser with great success.

A quick example (not tested). Note, you could use the -OfficePhone parameter below, for example, but it is easier to use the actual telephoneNumber attribute when you are concerned about blank values. This example has just one New-ADUser statement
if there are any attributes in the hash table, and one other if there are none.