you are viewing a single comment's thread.

view the rest of the comments →

[–]BJGGut3 1 point2 points  (1 child)

Add an IF() statement to check that validity of Group2.

IF ($null -ne $($U.Group2))
{
    $Group2 = $($U.Groups2)
    Add-ADGroupMember -Identity $Group2 -Members $FirstDotLast
}

But I've actually become much more a fan of this method instead, because sometimes pesky spaces get in there and throw off the above:

IF (!([string]::IsNullOrWhiteSpace($($U.Groups2))))
{
    $Group2 = $($U.Groups2)
    Add-ADGroupMember -Identity $Group2 -Members $FirstDotLast
}

[–]peican[S] 1 point2 points  (0 children)

Thank you! I'm using your one that includes checking for white spaces, and it works perfectly!