Welcome to Powergui.org - an open source community for Windows Powershell

PowerGUI.org PowerGUI.org and blogs

Forums » Active Directory and PowerShell

Thread: Import-csv file to create new AD Groups

This question is answered.


Permlink Replies: 4 - Pages: 1 - Last Post: Jan 19, 2011 11:13 AM by: Jeroen
Jeroen

Posts: 3
Registered: 1/19/11
Import-csv file to create new AD Groups
Posted: Jan 19, 2011 6:29 AM
 
  Click to reply to this thread Reply

Hi all!

I am very new to scripting and powershell in general. Unfortunatly I have a problem for a customer that I need to fix. I have to create 150 global security groups in AD and because Powershell is THE magic solution for every admin and we all have to learn it I definitly want to do it this way.

Ok so I created a csv file with the following parameter in Excel:

name ,parent,samaccountname,grouptype,groupscope,description
SG_TEST1,"OU=Test,DC=apple,DC=local",SG_TEST1,security,global,Applicatiegroep Test1
SG_TEST2,"OU=Test,DC=apple,DC=local",SG_TEST2,security,global,Applicatiegroep Test2
SG_TEST3,"OU=Test,DC=apple,DC=local",SG_TEST3,security,global,Applicatiegroep Test3
SG_TEST4,"OU=Test,DC=apple,DC=local",SG_TEST4,security,global,Applicatiegroep Test4

I see know that Excel throws everything in one colum and different lines, I seperated the colums in Excel, but the csv does it this way. I hope thats ok.

So the domainname is just a test domain and I am running this in a test environment. I installed the quest ActiveRoles AD PowerShell extensions and added them. When I type the following command in powershell or the powergui nothing happens. No errors, just enter and then a blinking cursor. The OU stays empty, no groups.

This is the script:

import-csv c:\test.csv | foreach {New-QADGroup -Name $_name -ParentContainer $_parent -SamAccountName $_samaccountname -GroupType $_grouptype -GroupScope $_groupscope -Description $_description}

I tried also to do the $_.name, so with a dot but also not the solution. Dubugging mode in Powergui does nothing.

Also running powershell in administrator mode. C: drive security settings maybe?

Can somebody help me please!

Thanks in advance!

Jeroen


Message was edited by: Jeroen


VictoriaFurman

Posts: 202
Registered: 8/14/07
Re: Import-csv file to create new AD Groups
Posted: Jan 19, 2011 7:09 AM   in response to: Jeroen
Helpful
  Click to reply to this thread Reply

There is seem to be an extra blank space in the CSV file you are using (right after "name "). Please remove it and try the following:

import-csv c:\test.csv | foreach {New-QADGroup -Name $_.name -ParentContainer $_.parent -SamAccountName $_.samaccountname -GroupType $_.grouptype -GroupScope $_.groupscope -Description $_.description}




Jeroen

Posts: 3
Registered: 1/19/11
Re: Import-csv file to create new AD Groups
Posted: Jan 19, 2011 7:26 AM   in response to: VictoriaFurman
 
  Click to reply to this thread Reply

Hi Victoria,

Thanks for the quick reply!

When I follow your suggestions at lease I get errors to go on! I get 25 times (there 25 groups in the test csv) this error:

New-QADGroup : Cannot validate argument on parameter 'ParentContainer'. The argument is null or empty. Supply an argument t
hat is not null or empty and then try the command again.
At C:\Users\Jengelander\AppData\Local\Temp\77baeadf-c2cf-4e2f-86c4-a5857ca59ac5.ps1:1 char:78
+ import-csv c:\test.csv | foreach {New-QADGroup -Name $_.name -ParentContainer <<<<  $_.parent -SamAccountName $_.samaccou
ntname -GroupType $_.grouptype -GroupScope $_.groupscope -Description $_.description}
    + CategoryInfo          : InvalidData: (:) [New-QADGroup], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Quest.ActiveRoles.ArsPowerShellSnapIn.Powershell.Cmdlets.Ne
   wGroupCmdlet

It looks like the parameter to parent colum is not excepted which is:

"OU=Test,DC=apple,DC=local"

Any ideas?

My domain name is apple.local. Don't ask :) And my OU is Test which is right underneath the domain tree, so no sub OU. Do I need to put it in "text"?

Message was edited by: Jeroen Message was edited by: Jeroen


VictoriaFurman

Posts: 202
Registered: 8/14/07
Re: Import-csv file to create new AD Groups
Posted: Jan 19, 2011 9:09 AM   in response to: Jeroen
Answered
  Click to reply to this thread Reply

I would double-check the header line in the CSV file.
Make sure it looks like this:
name,parent,samaccountname,grouptype,groupscope,description


Jeroen

Posts: 3
Registered: 1/19/11
Re: Import-csv file to create new AD Groups
Posted: Jan 19, 2011 11:13 AM   in response to: VictoriaFurman
 
  Click to reply to this thread Reply

Hi Victoria,

Thank you very much for the help! I made the cvs file again in notepad instead of excel and then I got a security error. After this I made sure the ntfs settings were ok and ran Powergui in administrator mode. It works now :)

Thanks again!

Kind regards,

Jeroen


Legend
MVP: 2501 + pts
Guru: 2001 - 2500 pts
Expert: 751 - 2000 pts
Enthusiast: 31 - 750 pts
Novice: 0 - 30 pts
Moderators
Helpful answer (5 pts)
Answered (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums