Your PowerGUI Community: Simplify your PowerShell related GUI and script editing needs.


Import-csv file to create new AD Groups

This question is answered

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
Verified Answer
  • I would double-check the header line in the CSV file.
    Make sure it looks like this:
    name,parent,samaccountname,grouptype,groupscope,description
All Replies
  • 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}

  • 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
  • I would double-check the header line in the CSV file.
    Make sure it looks like this:
    name,parent,samaccountname,grouptype,groupscope,description
  • 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