How to import groups in Active Directory with gidNumber using Powershell script/CSV file

Ahmed Qureshi 85 Reputation points
2023-06-23T07:41:04.0766667+00:00

Hi,

We want to import around 200 groups in Active Directory using Powershell script and CSV file where we have all attributes such as (name, path, scope, category, description and gidNumber) but it is giving us error following error:

New-ADGroup : A parameter cannot be found that matches parameter name 'gidNumber'.
At C:\share\ImportGroupsFromLdapToAD.ps1:21 char:17
+     New-ADGroup @groupProps
+                 ~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [New-ADGroup], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.NewADGroup

We are using following script:

Import-Module ActiveDirectory

#Import CSV
$groups = Import-Csv 'C:\Share\Import-Group-to-AD.csv'


# Loop through the CSV
    foreach ($group in $groups) {

    $groupProps = @{

      Name          = $group.name
      Path          = $group.path
      GroupScope    = $group.scope
      GroupCategory = $group.category
      Description   = $group.description
      gidNumber	    = $group.gidNumber
	
      }#end groupProps

Can any one please help us to import the groups with specified gidNumber in CSV. We appreciate your help.

Thanks

Windows for business | Windows Client for IT Pros | Directory services | Active Directory
0 comments No comments
{count} votes

Accepted answer
  1. Limitless Technology 44,766 Reputation points
    2023-06-23T14:14:41.7266667+00:00

    Hello there,

    To import groups into Active Directory with the gidNumber attribute using a PowerShell script and a CSV file, you can follow these steps:

    Prepare the CSV file: Create a CSV file that includes the necessary group information, including the group name and the corresponding gidNumber value. Ensure that the CSV file has the following column headers: "GroupName" and "GidNumber". Save the file with a suitable name, such as "groups.csv".

    Open PowerShell: Launch PowerShell with administrative privileges.

    Import the Active Directory module: Run the following command to import the Active Directory module:

    Import-Module ActiveDirectory

    Read the CSV file: Use the Import-Csv cmdlet to read the contents of the CSV file into a PowerShell variable. Adjust the path of the CSV file if needed.

    $groups = Import-Csv -Path "C:\Path\to\groups.csv"

    Loop through the groups and create them in Active Directory: Iterate over each row in the CSV file and create the corresponding groups in Active Directory using the New-ADGroup cmdlet. Set the gidNumber attribute for each group using the Set-ADGroup cmdlet.

    foreach ($group in $groups) {

    $groupName = $group.GroupName
    
    $gidNumber = $group.GidNumber
    
    New-ADGroup -Name $groupName -GroupScope Global
    
    Set-ADGroup -Identity $groupName -Add @{gidNumber = $gidNumber}
    

    }

    Verify the groups in Active Directory: You can verify that the groups have been created and the gidNumber attribute has been set correctly by checking Active Directory using tools like Active Directory Users and Computers or PowerShell commands.

    Ensure that you have the necessary permissions and appropriate domain connectivity to perform these actions. Additionally, review the PowerShell script and CSV file contents carefully to ensure they align with your requirements and conform to your organization's naming conventions and security policies.

    I used AI provided by ChatGPT to formulate part of this response. I have verified that the information is accurate before sharing it with you.

    Hope this resolves your Query !!

    --If the reply is helpful, please Upvote and Accept it as an answer–

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.