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

Posted on 2009-02-13
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)

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

Thanks for the help
Question by:Denver_IT
    1 Comment
    LVL 2

    Accepted Solution

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
    This article will show, step by step, how to integrate R code into a R Sweave document
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now