Ejemplo n.º 1
0
        public static async Task <bool> MoveGroupToOU(string GroupCode, string OUCode)
        {
            var command = new PowerShellCommand()
            {
                EC      = EC,
                Command = string.Format(@"Get-ADGroup '{0}' | Move-ADObject -TargetPath 'OU={1},OU=ESPACK,DC=SYSTEMS,DC=espackeuro,DC=com' ", GroupCode, OUCode)
            };

            return(await command.InvokeAsync());
        }
Ejemplo n.º 2
0
        public static async Task <bool> AddUserToGroup(string UserCode, string GroupCode, bool isContact = false, string GroupPath = DefaultPathAliases)
        {
            var command = new PowerShellCommand()
            {
                EC      = EC,
                Command = string.Format("$dlGroup = [adsi]'LDAP://CN={0},{1}';$dlUser = Get-ADObject -Filter {{{3} -eq '{2}'}};$dlGroup.Member.Add($dlUser.DistinguishedName);$dlGroup.psbase.CommitChanges()", GroupCode, GroupPath, UserCode, isContact ? "Name" : "SamAccountName")
            };

            return(await command.InvokeAsync());
        }
Ejemplo n.º 3
0
        public static async Task <bool> RemoveUserFromGroup(string UserCode, string GroupCode, string GroupPath = DefaultPathAliases)
        {
            var command = new PowerShellCommand()
            {
                EC      = EC,
                Command = string.Format("Get-ADGroup -LDAPFilter '(SAMAccountName={0})' -SearchBase '{1}' | remove-adgroupmember -Member '{2}'  -Confirm:$false", GroupCode, GroupPath, UserCode)
            };

            return(await command.InvokeAsync());
        }
Ejemplo n.º 4
0
        public static async Task <bool> CreateOrganizationalUnit(string OUCode, string OUDescription, string Path)
        {
            var command = new PowerShellCommand()
            {
                EC      = EC,
                Command = string.Format(@"New-ADOrganizationalUnit -Name '{0}'  -DisplayName '{1}' -Description '{1}' -path '{2}'", OUCode, OUDescription, Path)
            };
            var _res = await command.InvokeAsync();

            return(_res);
        }
Ejemplo n.º 5
0
        public static async Task <bool> CleanGroup(string GroupName)
        {
            var command = new PowerShellCommand()
            {
                EC      = EC,
                Command = string.Format("Get-ADGroupMember '{0}'| ForEach-Object {{Remove-ADGroupMember '{0}' $_ -Confirm:$false}}", GroupName)
            };
            var _res = await command.InvokeAsync();

            return(_res);
        }
Ejemplo n.º 6
0
        public static async Task <bool> DisableUser(string UserCode)
        {
            var command = new PowerShellCommand()
            {
                EC      = EC,
                Command = string.Format("Disable-ADAccount -Identity {0}", UserCode)
            };
            var _res = await command.InvokeAsync();

            Results = command.SResults;
            return(_res);
        }
Ejemplo n.º 7
0
        public static async Task <bool> CheckUser(string UserCode)
        {
            var command = new PowerShellCommand()
            {
                EC      = EC,
                Command = "Get-ADUser -Filter {sAMAccountName -eq '" + UserCode + "'}"
            };
            var _res = await command.InvokeAsync();

            Results = command.SResults;
            return(Results != "");
        }
Ejemplo n.º 8
0
        public static async Task <bool> EnableGroup(string GroupCode)
        {
            var command = new PowerShellCommand()
            {
                EC      = EC,
                Command = string.Format(@"if (![bool](Get-DistributionGroup -Identity '{0}' -ErrorAction SilentlyContinue)) {{Enable-DistributionGroup -Identity '{0}';}}", GroupCode)
            };
            var _res = await command.InvokeAsyncExchange();

            Results = command.SResults;
            return(_res);
        }
Ejemplo n.º 9
0
        public static async Task <bool> CreateUser(string Name, string Surname, string UserCode, string Password, string EmailAddress, string COD3)
        {
            var division = string.Format("{0}/{1}", EmailAddress.Substring(EmailAddress.IndexOf('@') + 1), UserCode);
            var command  = new PowerShellCommand()
            {
                EC      = EC,
                Command = string.Format("New-ADUser -Name '{0} {1}' -GivenName '{0}' -Surname '{1}' -SamAccountName '{2}' -DisplayName '{0} {1}' -EmailAddress '{4}' -UserPrincipalName '{2}@systems.espackeuro.com' -Division '{5}' -PasswordNeverExpires:$True -AccountPassword (ConvertTo-SecureString -AsPlainText '{3}' -Force) -PassThru | Enable-ADAccount;", Name, Surname, UserCode, Password, EmailAddress, division)
            };
            var _res = await command.InvokeAsync();

            Results = command.SResults;
            return(_res);
        }
Ejemplo n.º 10
0
        public static async Task <bool> CheckOrganizationalUnit(string OUCode)
        {
            var command = new PowerShellCommand()
            {
                EC      = EC,
                Command = string.Format(@"Get-ADOrganizationalUnit -LDAPFilter '(Name={0})'", OUCode)
            };
            var _res = await command.InvokeAsync();

            Results = command.SResults;
            _res    = Results != "";
            return(_res);
        }
Ejemplo n.º 11
0
        public static async Task <bool> CheckGroup(string GroupCode, string Path = DefaultPath)
        {
            var command = new PowerShellCommand()
            {
                EC      = EC,
                Command = string.Format(@"Get-ADGroup -LDAPFilter '(SAMAccountName={0})' -SearchBase '{1}'", GroupCode, Path)
            };
            var _res = await command.InvokeAsync();

            Results = command.SResults;
            _res    = Results != "";
            return(_res);
        }
Ejemplo n.º 12
0
        public static async Task <bool> CheckObject(string ObjectName, string ObjectType, string Path = "OU=ESPACK,DC=SYSTEMS,DC=espackeuro,DC=com")
        {
            var command = new PowerShellCommand()
            {
                EC      = EC,
                Command = string.Format(@"Get-ADObject -Filter {{(Name -eq '{0}') -and (objectClass -eq '{1}')}} -SearchBase '{2}' -SearchScope OneLevel", ObjectName, ObjectType, Path)
            };
            var _res = await command.InvokeAsync();

            Results = command.SResults;
            _res    = Results != "";
            return(_res);
        }
Ejemplo n.º 13
0
        public static async Task <bool> CreateGroup(string GroupCode, string GroupName, string GroupCategory, string Path, Dictionary <string, string> AttributeList = null) //= "OU=ESPACK,DC=SYSTEMS,DC=espackeuro,DC=com")
        {
            var command = new PowerShellCommand()
            {
                EC      = EC,
                Command = string.Format(@"New-ADGroup -Name '{1}' -SamAccountName '{0}' -GroupCategory {2} -GroupScope Universal -DisplayName '{1}' -Path '{3}'", GroupCode, GroupName, GroupCategory, Path)
            };
            var _res = await command.InvokeAsync();

            if (AttributeList != null)
            {
                _res = await UpdateObject(GroupCode, "group", Path, AttributeList);
            }

            return(_res);
        }
Ejemplo n.º 14
0
        public static async Task <bool> PropertyAdd(string Code, string PropertyName, string PropertyValue, bool CleanFirst)
        {
            string commandString = string.Format("$object = Get-ADObject -LDAPFilter '(SAMAccountName={0})'; ", Code);

            commandString += CleanFirst ? string.Format("Set-ADObject -Identity $object -Clear {0}; ", PropertyName) : "";
            commandString += string.Format("Set-ADObject -Identity $object -Add @{{{0}={1}}}; ", PropertyName, PropertyValue);
            var command = new PowerShellCommand()
            {
                EC      = EC,
                Command = commandString
            };
            var _res = await command.InvokeAsync();

            Results = command.SResults;
            return(_res);
        }
Ejemplo n.º 15
0
        public static async Task <bool> CreateObject(string ObjectName, string ObjectType, string Path = "OU=ESPACK,DC=SYSTEMS,DC=espackeuro,DC=com", Dictionary <string, string> AttributeList = null)
        {
            var command = new PowerShellCommand()
            {
                EC      = EC,
                Command = string.Format(@"New-ADObject -Name '{0}' -Type '{1}' -Path '{2}';", ObjectName, ObjectType, Path)
            };
            var _res = await command.InvokeAsync();

            if (AttributeList != null)
            {
                _res = await UpdateObject(ObjectName, ObjectType, Path, AttributeList);
            }

            return(_res);
        }
Ejemplo n.º 16
0
        public static async Task <bool> UpdateUser(string Name, string Surname, string UserCode, string Password, string EmailAddress, string COD3)
        {
            var division = string.Format("{1}/{2}", COD3.ToLower(), EmailAddress.Substring(EmailAddress.IndexOf('@') + 1), UserCode);
            var command  = new PowerShellCommand()
            {
                EC      = EC,
                Command = string.Format(@"
Enable-ADAccount -Identity '{0}';
Get-ADUser -Identity '{0}' | Rename-ADObject -NewName '{1} {2}' ;
Get-ADUser -Identity '{0}' | Set-ADUser -DisplayName '{1} {2}' -GivenName '{1}' -Surname '{2}' {4} -Division '{5}' -PasswordNeverExpires:$True;
Get-ADUser -Identity '{0}' | Set-ADAccountPassword -Reset -NewPassword (ConvertTo-SecureString -AsPlainText '{3}' –Force);
", UserCode, Name, Surname, Password, EmailAddress != "" ? "-EmailAddress " + EmailAddress : "", division)
            };
            var _res = await command.InvokeAsync();

            Results = command.SResults;
            return(_res);
        }
Ejemplo n.º 17
0
        public static async Task <bool> Commit(Collection <ServiceCommand> serviceCommands)
        {
            var command = new PowerShellCommand()
            {
                EC = EC
            };
            bool _res;

            try
            {
                _res = await command.InvokeList(serviceCommands, EC.WSMan);
            } catch (Exception ex)
            {
                return(false);

                throw ex;
            }
            return(_res);
        }
Ejemplo n.º 18
0
        public static async Task <bool> UpdateObject(string ObjectName, string ObjectType, string Path = "OU=ESPACK,DC=SYSTEMS,DC=espackeuro,DC=com", Dictionary <string, string> AttributeList = null)
        {
            string _attributeListString = "";

            //string _attributeKeys = "";
            if (AttributeList != null)
            {
                _attributeListString = string.Join(";", AttributeList.Select(r => string.Format("{0}='{1}'", r.Key, r.Value)).ToArray());
                //_attributeKeys = string.Join(",", AttributeList.Select(r => r.Key).ToArray());
            }
            var command = new PowerShellCommand()
            {
                EC      = EC,
                Command = string.Format("Get-ADObject -LDAPFilter '(Name={0})' -SearchBase '{2}'| Set-ADObject -Add @{{{1}}};", ObjectName, _attributeListString, Path)
            };
            var _res = await command.InvokeAsync();

            return(_res);
        }