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.

Script Repository

Import group members from CSV file

February 18, 2021 Views: 4906

The script adds AD objects specified in a CSV file to a group.

To import group members using Adaxes, you can create a custom command configured for the Group object type that runs the script. For more information, see Create a Custom Command.

Parameter:

  • $csvFilePath - Specifies the path to the CSV file to import.
Note: You can use value references (e.g. %name%) to insert the properties of the group as a part of the CSV file name. For example, if you specify the following path \\server\share\%name%.csv, and execute the script on a group with name Account Administrators, the resulting path will be \\SERVER\share\Account Administrators.

CSV File Sample:

Name,sAMAccountName,Telephone Number
William Robertson,wrobertson,+4420 7845 1232
Susan John,sjohn,+4420 7845 1234
Elizabeth Smith,esmith,+4420 7845 1234
Alexaner Hamilton,ahamilton,+4420 7845 1256

Note: The objects to add to the group will be identified by their name specified in the Name column, any other columns present in the CSV file will be ignored.
To identify objects, use one of the following properties:
  • Distinguished Name (example: CN=SaraDavis ,CN=Users,DC=corp,DC=contoso,DC=com)
  • GUID (example: 599C3D2E-F72D-4D20-8A88-030D99495F20)
  • Security Identifier (example: S-1-5-21-3165297888-301567370-576410423-1103)
  • SAM Account Name (example:saradavis)
Note: The script uses cmdlets from Adaxes PowerShell module for Active Directory. To run the script, you need to install the PowerShell Module for Active Directory component of Adaxes.
Edit Remove
PowerShell
Import-Module Adaxes

$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 content
$csvFile = Import-Csv $csvFilePath

foreach ($user in $csvFile)
{
   try
   {
       Add-AdmGroupMember -Identity "%distinguishedName%" -Members $user.Name -Adaxesservice localhost -ErrorAction Stop -Confirm:$False
   }
   catch
   {
       $Context.LogMessage($_.Exception.Message, "Warning")
   }
}
Comments 0
Leave a comment
Loading...

Got questions?

Support Questions & Answers