The format was simple:
user1A snippet of the code is below:
user2
user3
//using log4net;...and main:
//using ActiveDs;
public void Run()
{
foreach (AdUser user in ReadUsers())
{
using (user)
{
DictionaryuserGroups = GetUserGroupsDn(user.Entry);
foreach (string groupDn in _groupsToAddUserTo.Keys)
{
if (userGroups.ContainsKey(groupDn))
continue; // User already in this group
AdGroup group = _groupsToAddUserTo[groupDn];
try
{
group.NativeObject.Add(user.Entry.Path);
log.Info(string.Format("User: {0} added to Group: {1}",
user.Entry.Properties["sAMAccountName"][0], group.NativeObject.Name));
}
catch (Exception)
{
log.Error(string.Format("User: {0} can't be added to Group: {1}. Possibly this is it's primary group already.",
user.Entry.Properties["sAMAccountName"][0], group.NativeObject.Name));
}
}
}
}
}
private void Run(string[] args)Anyone want to show how this can be done in powershell in 25 or so lines?
{
//logging removed for brevity in snippet
Settings settings = SettingsReader.ReadFromConfig();
Adder adder = new Adder(settings);
adder.UsersToProcess = ReadUsersToProcess(settings.UsersFilePath);
adder.Run();
}
No comments:
Post a Comment