Hello! We doing some changes to our company this days, and we need to delete and add a lot of groups on the users. I was going to use this script to remove all access groups on the user (Greate to have a log, if the user is missing some access, we can easily see what access he had)
$filePath = "C:\Reports\Useradm\Disabledusers\%username%.txt" # TODO: modify me
# Get all groups user is a direct member of
$groupGuids = $Context.TargetObject.GetEx("adm-DirectMemberOfGuid")
# Get the Primary Group ID
$primaryGroupId = $Context.TargetObject.Get("primaryGroupID")
# Create a plain text report
$report = New-Object "System.Text.StringBuilder"
$report.Append("The user was removed from the following groups:")
foreach ($groupGuidBytes in $groupGuids)
{
# Bind to the group
$groupGuid = New-Object "System.Guid" (,$groupGuidBytes)
$groupGuid = $groupGuid.ToString("B")
$groupPath = "Adaxes://<GUID=$groupGuid>"
$group = $Context.BindToObject($groupPath)
# Skip the group if it is the user's Primary Group
if ($group.Get("primaryGroupToken") -eq $primaryGroupId)
{
continue
}
# Remove user from the group
$group.Remove($Context.TargetObject.AdsPath)
# Add the group to the report
$report.AppendLine()
$report.Append($group.Get("name"))
}
# Create a new text
$file = New-Item -Path $filePath -ItemType File
# Save the report to the file
Add-Content $file $report.ToString()
My Problem. We have a system that only syncs every 24 hour for some reason, so we cant remove the groups that gives access to this system. I am having problems implementing a do not delete variable in this script for other then the primary group sadly, is this something you guys could help me solve?
And a bonus question :) What is the best way of deleting and adding new groups true Adaxes? I am now (before moving user) removing all groups and then (after moved) it will add all groups based on Location, title, department and Division.
I see some add access based on templates users(Is this only how you are used to do things, or is there a best practice in Adaxes?)
Thanks for any help :)
Best regards
Tomada