Пример #1
0
        public static System.DirectoryServices.AccountManagement.GroupPrincipal New_DomainGroup(Args_New_DomainGroup args = null)
        {
            if (args == null)
            {
                args = new Args_New_DomainGroup();
            }

            var ContextArguments = new Args_Get_PrincipalContext
            {
                Identity   = args.SamAccountName,
                Domain     = args.Domain,
                Credential = args.Credential
            };
            var Context = GetPrincipalContext.Get_PrincipalContext(ContextArguments);

            if (Context != null)
            {
                var Group = new System.DirectoryServices.AccountManagement.GroupPrincipal(Context.Context);

                // set all the appropriate group parameters
                Group.SamAccountName = Context.Identity;

                if (!string.IsNullOrEmpty(args.Name))
                {
                    Group.Name = args.Name;
                }
                else
                {
                    Group.Name = Context.Identity;
                }
                if (!string.IsNullOrEmpty(args.DisplayName))
                {
                    Group.DisplayName = args.DisplayName;
                }
                else
                {
                    Group.DisplayName = Context.Identity;
                }

                if (!string.IsNullOrEmpty(args.Description))
                {
                    Group.Description = args.Description;
                }

                Logger.Write_Verbose($@"[New-DomainGroup] Attempting to create group '{args.SamAccountName}'");
                try
                {
                    Group.Save();
                    Logger.Write_Verbose($@"[New-DomainGroup] Group '{args.SamAccountName}' successfully created");
                    return(Group);
                }
                catch (Exception e)
                {
                    Logger.Write_Warning($@"[New-DomainGroup] Error creating group '{args.SamAccountName}' : {e}");
                }
            }

            return(null);
        }
Пример #2
0
 public static System.DirectoryServices.AccountManagement.GroupPrincipal New_DomainGroup(Args_New_DomainGroup args = null)
 {
     return(NewDomainGroup.New_DomainGroup(args));
 }