Example #1
0
        public DomainJoin(NewUser nup, Credentials creds, digestFQDN l, bool where, string[] g)
        {
            o365creds = creds;
            location  = l;
            group     = g;
            if (where == false)
            {
                Console.WriteLine("adding local user");
                dmn       = System.Environment.MachineName;
                ctx       = ContextType.Machine;
                container = null;
            }
            else
            {
                aduser = true;
                Console.WriteLine("adding AD user");
                uname = creds.username;
                pwd   = creds.password;
                dmn   = location.dmn;

                ctx       = ContextType.Domain;
                container = string.Concat("CN=Users" + "," + location.container);
                Console.WriteLine(container);
            }
            nu = nup;
            Console.WriteLine("Adding to:" + dmn);
            join();
        }
Example #2
0
        public NewUser(digestFQDN netinfo, string full_name)
        {
            home = netinfo;
            string[] nameTokens = full_name.Split(' ');

            first_name = nameTokens.First <string>();
            last_name  = nameTokens.Last <string>();

            log_on_name = generate_valid_log_on_name(first_name, last_name);
            UPN         = generate_valid_UPN(log_on_name);
        }
Example #3
0
        static void Main(string[] args)
        {
            string full_name = "nothing";

            bool where = false;
            bool   multiadd        = false;
            bool   prompt_for_user = true;
            string filename        = null;

            string[]    group   = { "Users" };
            Credentials creds   = null;
            digestFQDN  netinfo = new digestFQDN();

            if (args.Length == 0)
            {
                Console.WriteLine("run with -? for settings");
            }
            else
            {
                int count = 0;
                foreach (string i in args)
                {
                    if (i == "-?")
                    {
                        Console.WriteLine("usage: executable.exe -u FirstName LastName\n" +
                                          "-?         show settings\n" +
                                          "-u         New User's Name\n" +
                                          "-d         Make a domain user    Default: local\n" +
                                          "-b         read user list from a file\n" +
                                          "-g         {GroupName1 GroupName2 Groupname3}   Specify a user group  Default: Users\n" +
                                          "-#         Make Administrator");

                        Environment.Exit(0);
                    }
                    if (i == "-u")
                    {
                        try
                        {
                            full_name       = args[count + 1] + " " + args[count + 2];
                            prompt_for_user = false;
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message.ToString() + "- Did you specify a full name?");
                        }
                    }
                    if (i == "-l")
                    {
                        where = false;
                    }
                    if (i == "-d")
                    {
                        creds = new Credentials();
                        where = true;
                    }
                    if (i == "-b")
                    {
                        try
                        {
                            filename        = args[count + 1];
                            multiadd        = true;
                            prompt_for_user = false;
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message.ToString() + "- Did you specify a filename?");
                        }
                    }
                    if (i == "-g")
                    {
                        Console.WriteLine("-g detected");
                        Queue <String> groupqueue = new Queue <string>();
                        groupqueue.Enqueue("Users");
                        for (int groupcount = count + 1; groupcount < args.Length; groupcount++)
                        {
                            if (args[groupcount].ToCharArray().First <char>() == '-')
                            {
                                break;
                            }
                            else
                            {
                                groupqueue.Enqueue(args[groupcount]);
                            }
                        }
                        group = groupqueue.ToArray();
                    }
                    if (i == "-#")
                    {
                        group[0] = "Administrators";
                    }
                    count++;
                }
            }

            if (prompt_for_user == true)
            {
                Console.Write("User full name: ");
                full_name = Console.ReadLine();
            }
            if (multiadd == false)
            {
                NewUser    user = new NewUser(netinfo, full_name);
                DomainJoin dj   = new DomainJoin(user, creds, netinfo, where, group);
            }
            else //Add users from a file (will not make administrators)
            {
                FileStream   fs = System.IO.File.OpenRead(filename);
                StreamReader sr = new StreamReader(fs);

                while (!sr.EndOfStream)
                {
                    NewUser    user = new NewUser(netinfo, sr.ReadLine());
                    DomainJoin dj   = new DomainJoin(user, creds, netinfo, where, group);
                }
            }
        }