Creating groups from a CSV using powershell

Posted on 2011-10-28
Medium Priority
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
  • 2
  • 2
LVL 37

Accepted Solution

Neil Russell earned 2000 total points
ID: 37043833
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

ID: 37043852
An  hour of ripping my hair out. Stupid DOTs !!

Gracefully hands over the 500.

Thanks Neilsr
LVL 37

Expert Comment

by:Neil Russell
ID: 37043873
Your welcome. Easily done, I have no hair left now due to such stupid mistakes :P

Author Comment

ID: 37043910
lol. Sorry 1 more thing..

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Loops Section Overview

839 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