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,Telephone Number
susanjohn,+4420 7845 1234
599C3D2E-F72D-4D20-8A88-030D99495F20,+4420 7845 1234
S-1-5-21-3165297888-301567370-576410423-1103,+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.
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
{
$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")
}
}