locked
Create ADGroups from csv file RRS feed

  • Question

  • Hi,

    I make a script in powershell to add a lot off groups from csv file, but it's doesn't work...

    Import-Module ActiveDirectory
    $filepath = 'C:\script\READY.csv'
    $groups = Import-Csv $filepath -Delimiter ';'
    foreach ($group in $groups) {
    $groupName = $group.Name
    $groupCategory = $group.GroupCategory
    $groupScope = $group.GroupScope
    $OU = $group.OU
    
    
    New-ADGroup `
    -Name $groupName `
    -SamAccountName $groupName `
    -DisplayName $groupName `
    -GroupCategory $groupCategory `
    -GroupScope $groupScope `
    -Path $OU
    
    }

    Error:

     
    New-ADGroup : The server is unwilling to process the request
    At line:11 char:1
    + New-ADGroup -Name $groupName -SamAccountName $groupName -DisplayName  ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (CN=Group1,OU=GRO...test,DC=local:String) [New-ADGroup], ADException
        + FullyQualifiedErrorId : ActiveDirectoryServer:0,Microsoft.ActiveDirectory.Management.Commands.NewADGroup

    Someone know how to make it to work?

    Friday, June 29, 2018 8:12 AM

All replies

  • Empty fields in your CSV.  Fix the CSV.


    \_(ツ)_/

    Friday, June 29, 2018 8:33 AM
  • I don't have any empty fields.

    This is test file:

    Name;GroupCategory;GroupScope;OU
    Group1;Distribution;Universal;OU=3.GROUPS,OU=London,DC=test,DC=local
    Iveco;Distribution;Universal;OU=GROUPS,OU=Metro,OU=London,DC=test,DC=local



    Friday, June 29, 2018 9:40 AM
  • Then you most likely have an issue with your OU strings.


    \_(ツ)_/

    Friday, June 29, 2018 9:48 AM
  • Change the test file column name "Name;GroupCategory;GroupScope;OU" into "Name;GroupCategory;GroupScope;Path"

    Friday, June 29, 2018 10:35 AM