Creating groups from a CSV using powershell

Posted on 2011-10-28
Last Modified: 2012-05-12
I am trying to create set of AD groups from a csv file
It should be straight forward but I am going wrong somewhere.
Can someone point me in the right direction.

I run this ps command
import-csv c:\admin\newgroups.csv | foreach {new-adgroup -Name $_Name -Description $_Description -GroupCategory Security -groupscope Global -Path "OU=Security Groups,dc=company,dc=com"}

MY CSV file contains

"Index - ABC Offshore Ltd","ABC Offshore Ltd"
"Index - DEF Inland","DEF Inland"

I get this error when run
New-ADGroup : Cannot validate argument on parameter 'Name'. The argument is null or empty. Supply an argument that is n
ot null or empty and then try the command again.
At line:1 char:63

If I use the command import-csv c:\admin\newgroups.csv it returns the table of csv contents ok.
Question by:Rodders1000
    LVL 37

    Accepted Solution

    import-csv c:\admin\newgroups.csv | foreach {new-adgroup -Name $_.Name -Description $_.Description -GroupCategory Security -groupscope Global -Path "OU=Security Groups,dc=company,dc=com"}

    You are missing those . that I have put in above.


    Author Closing Comment

    An  hour of ripping my hair out. Stupid DOTs !!

    Gracefully hands over the 500.

    Thanks Neilsr
    LVL 37

    Expert Comment

    Your welcome. Easily done, I have no hair left now due to such stupid mistakes :P

    Author Comment

    lol. Sorry 1 more thing..

    If my title column had a space in it. Is it as simple as $_."Spaced Name" ?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    This article is intended to be a 2 part Primer to get someone up and running quickly and efficiently in Powershell, but also including small useful tips that you might not find elsewhere.   One of the things I see often is people starting out usi…
    Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    737 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

    22 Experts available now in Live!

    Get 1:1 Help Now