Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 251
  • Last Modified:

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

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)

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

Thanks for the help
1 Solution
Denver_ITAuthor Commented:
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.

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now