Script repository

Import group members from CSV file

Updated on: Jan 18, 2026, Views: 11229

Import data

The script adds AD objects specified in a CSV file to the target group. To execute the script, create a business rule, custom command or scheduled task configured for the Group object type.

In the script, the $csvFilePath variable specifies the path to the CSV file to import.

The imported CSV file must contain the Name column. The column values will be used to identify the objects to add to the group.

Objects can be identified in the Name column by using the following properties:

  • Distinguished name (e.g. CN=SaraDavis,CN=Users,DC=corp,DC=contoso,DC=com)
  • GUID (e.g. 599C3D2E-F72D-4D20-8A88-030D99495F20)
  • Security identifier (e.g. S-1-5-21-3165297888-301567370-576410423-1103)
  • sAMAccountName (e.g. saradavis)

CSV file sample

Name,Operation
pmason,Disable
"John Brown,CN=Users,DC=corp,DC=contoso,DC=com",Delete
S-1-5-21-3165297888-301567370-576410423-1103,Disable

To use the script, install the Adaxes PowerShell module on the computer where the service runs.

$csvFilePath = "\\SERVER\share\MyCsvFile.csv" # TODO: Modify me

# Check file path.
if (!(Test-Path -Path $csvFilePath))
{
    $Context.LogMessage("File '$csvFilePath' not found.", "Warning")
    return
}

# Import CSV file.
$csvFile = Import-Csv $csvFilePath

foreach ($user in $csvFile)
{
   try
   {
       $domainName = $Context.GetObjectDomain("%distinguishedName%")
       Add-AdmGroupMember -Identity "%distinguishedName%" -Members $user.Name -Adaxesservice localhost -ErrorAction Stop -Confirm:$False -Server $domainName
   }
   catch
   {
       $Context.LogMessage($_.Exception.Message, "Warning")
   }
}

Comments 0

You must be signed in to comment.

    Got questions?

    Support Questions & Answers

    We use cookies to improve your experience.
    By your continued use of this site you accept such use.
    For more details please see our privacy policy and cookies policy.