We help IT Professionals succeed at work.

Adding a user with a comma in his name to a group...

Denver_IT
Denver_IT asked
on
Medium Priority
259 Views
Last Modified: 2012-05-06
I have been working on several scripts that read a CSV and create a series of objects.

I have been able to:
Create the Exchange mailbox and user account
Set the Exchange Custom Attributes
Set the User Arrributes
Create a group for that user
Create an OU based on that User
Create a GPO based on that user and link it to the OU
Add all the accounts I want to add to the group created save for one (the user account I created).

The user is listed Last, First in the OU and I am wondering if the comma is giving a problem when trying to add it to the group
Do I have to put quotes around the First, Last?  If so how do I put that in my script?

Here is the actual example:
import-csv ImportUsers.csv | foreach {
($Alias = $_.Alias)
($Name = $_.Name)
$AddUser = ("CN=" + $Name + ",OU=" + $Alias + ",OU=New Users" + $Domain)
$group.Member.Add("$AddUser")
$group.setInfo()
}

The output looks correct if I display $AddUser: CN=Last, First,OU=FLast,OU=New Users,DC=domain,DC=com

Thanks for the help
Comment
Watch Question

Figured it out!  I needed to put tripple quotes in the CSV for the name field.  This poses a problem with the other scripts that run on this CSV as it will create a user account with quotes around the name however I changed the varriable to $name2 and added this field into the CSV with the reipple quotes.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.