Script repository
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,DisableTo 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.