예제 #1
0
        private bool GetADRootDSEBeginCSRoutine()
        {
            bool flag;
            Collection <string> strs = new Collection <string>();

            string[] item = this._cmdletParameters["Properties"] as string[];
            strs.Add("*");
            if (item != null)
            {
                for (int i = 0; i < (int)item.Length; i++)
                {
                    strs.Add(item[i]);
                }
            }
            ADObjectSearcher aDObjectSearcher = null;

            using (aDObjectSearcher)
            {
                try
                {
                    aDObjectSearcher = new ADObjectSearcher(this.GetSessionInfo());
                    ADRootDSE rootDSE = aDObjectSearcher.GetRootDSE(strs);
                    rootDSE.SessionInfo = base.GetCmdletSessionInfo().ADSessionInfo;
                    base.WriteObject(rootDSE);
                    flag = true;
                }
                catch (ADException aDException1)
                {
                    ADException aDException = aDException1;
                    base.WriteError(ADUtilities.GetErrorRecord(aDException, "GetADRootDSE:BeginProcessing:ADError", null));
                    flag = false;
                }
                catch (AuthenticationException authenticationException1)
                {
                    AuthenticationException authenticationException = authenticationException1;
                    base.WriteError(ADUtilities.GetErrorRecord(authenticationException, "GetADRootDSE:BeginProcessing:InvalidCredentials", null));
                    flag = false;
                }
            }
            return(flag);
        }
예제 #2
0
        private bool GetADDCBeginDiscoverCSRoutine()
        {
            bool flag;

            if (base.ParameterSetName == "DiscoverByService")
            {
                ADDiscoverDomainControllerOptions aDDiscoverDomainControllerOption = ADDiscoverDomainControllerOptions.None;
                ADDiscoverableService[]           service = this._cmdletParameters.Service;
                ADMinimumDirectoryServiceVersion? item    = (ADMinimumDirectoryServiceVersion?)(this._cmdletParameters["MinimumDirectoryServiceVersion"] as ADMinimumDirectoryServiceVersion?);
                string str   = this._cmdletParameters["SiteName"] as string;
                string item1 = this._cmdletParameters["DomainName"] as string;
                if (this._cmdletParameters.GetSwitchParameterBooleanValue("NextClosestSite"))
                {
                    aDDiscoverDomainControllerOption = aDDiscoverDomainControllerOption | ADDiscoverDomainControllerOptions.TryNextClosestSite;
                }
                if (this._cmdletParameters.GetSwitchParameterBooleanValue("ForceDiscover"))
                {
                    aDDiscoverDomainControllerOption = aDDiscoverDomainControllerOption | ADDiscoverDomainControllerOptions.ForceDiscover;
                }
                if (this._cmdletParameters.GetSwitchParameterBooleanValue("AvoidSelf"))
                {
                    aDDiscoverDomainControllerOption = aDDiscoverDomainControllerOption | ADDiscoverDomainControllerOptions.AvoidSelf;
                }
                if (this._cmdletParameters.GetSwitchParameterBooleanValue("Writable"))
                {
                    aDDiscoverDomainControllerOption = aDDiscoverDomainControllerOption | ADDiscoverDomainControllerOptions.Writable;
                }
                try
                {
                    ADEntity aDEntity = DomainControllerUtil.DiscoverDomainController(str, item1, service, aDDiscoverDomainControllerOption | ADDiscoverDomainControllerOptions.ReturnDnsName, item);
                    try
                    {
                        ADDiscoverDomainControllerOptions aDDiscoverDomainControllerOption1 = aDDiscoverDomainControllerOption;
                        aDDiscoverDomainControllerOption1 = aDDiscoverDomainControllerOption1 & (ADDiscoverDomainControllerOptions.AvoidSelf | ADDiscoverDomainControllerOptions.TryNextClosestSite | ADDiscoverDomainControllerOptions.Writable | ADDiscoverDomainControllerOptions.ReturnDnsName | ADDiscoverDomainControllerOptions.ReturnFlatName);
                        ADEntity aDEntity1 = DomainControllerUtil.DiscoverDomainController(str, item1, service, aDDiscoverDomainControllerOption1 | ADDiscoverDomainControllerOptions.ReturnFlatName, item);
                        if (aDEntity.InternalProperties.Contains("DiscoveryInternalPropertyDCAddress") && aDEntity1.InternalProperties.Contains("DiscoveryInternalPropertyDCAddress") && string.Equals((string)aDEntity.InternalProperties["DiscoveryInternalPropertyDCAddress"].Value, (string)aDEntity1.InternalProperties["DiscoveryInternalPropertyDCAddress"].Value))
                        {
                            aDEntity.Add("Name", aDEntity1["Name"].Value);
                        }
                    }
                    catch (ADException aDException1)
                    {
                        ADException aDException = aDException1;
                        DebugLogger.LogError("GetADDomainController", aDException.ToString());
                    }
                    CmdletSessionInfo cmdletSessionInfo = new CmdletSessionInfo();
                    this._factory.SetCmdletSessionInfo(cmdletSessionInfo);
                    ADDomainController aDDomainController = this._factory.Construct(aDEntity, new AttributeSetRequest(true));
                    base.WriteObject(aDDomainController);
                    return(false);
                }
                catch (ADException aDException3)
                {
                    ADException aDException2 = aDException3;
                    int         errorCode    = aDException2.ErrorCode;
                    base.WriteError(new ErrorRecord(aDException2, string.Concat("GetADDomainController:BeginProcessingOverride:DiscoverDC:", errorCode.ToString()), ErrorCategory.ObjectNotFound, null));
                    flag = false;
                }
                return(flag);
            }
            else
            {
                return(true);
            }
        }
        private bool SetADPrincipalGroupMembershipEndCSRoutine()
        {
            string defaultPartitionPath;
            string str  = null;
            string str1 = null;
            string str2 = null;
            SetADPrincipalGroupMembershipOperationType setADPrincipalGroupMembershipOperationType = this._operationType;

            switch (setADPrincipalGroupMembershipOperationType)
            {
            case SetADPrincipalGroupMembershipOperationType.AddGroupMembership:
            {
                str  = string.Format(CultureInfo.CurrentCulture, StringResources.AddADPrincipalGroupMembershipShouldProcessDescription, new object[0]);
                str2 = string.Format(CultureInfo.CurrentCulture, StringResources.AddADPrincipalGroupMembershipShouldProcessCaption, new object[0]);
                str1 = string.Format(CultureInfo.CurrentCulture, StringResources.AddADPrincipalGroupMembershipShouldProcessWarning, new object[0]);
                break;
            }

            case SetADPrincipalGroupMembershipOperationType.RemoveGroupMembership:
            {
                str  = string.Format(CultureInfo.CurrentCulture, StringResources.RemoveADPrincipalGroupMembershipShouldProcessDescription, new object[0]);
                str2 = string.Format(CultureInfo.CurrentCulture, StringResources.RemoveADPrincipalGroupMembershipShouldProcessCaption, new object[0]);
                str1 = string.Format(CultureInfo.CurrentCulture, StringResources.RemoveADPrincipalGroupMembershipShouldProcessWarning, new object[0]);
                break;
            }
            }
            if (base.ShouldProcessOverride(str, str1, str2))
            {
                ADPrincipal[]  array    = this._validExtendedPrincipalList.ToArray();
                List <ADGroup> aDGroups = new List <ADGroup>();
                foreach (SetADPrincipalGroupMembership <P> .ADGroupPartitionDNPair aDGroupPartitionDNPair in this._validExtendedGroupPartitionPairList)
                {
                    if (aDGroupPartitionDNPair.PartitionDN == null)
                    {
                        defaultPartitionPath = this.GetDefaultPartitionPath();
                    }
                    else
                    {
                        defaultPartitionPath = aDGroupPartitionDNPair.PartitionDN;
                    }
                    string str3 = defaultPartitionPath;
                    try
                    {
                        object[] group = new object[4];
                        group[0] = aDGroupPartitionDNPair.Group;
                        group[1] = array;
                        group[2] = str3;
                        group[3] = false;
                        base.InvokeCommand.InvokeScript(this._command.ToString(), false, PipelineResultTypes.None, null, group);
                    }
                    catch (RuntimeException runtimeException1)
                    {
                        RuntimeException runtimeException  = runtimeException1;
                        object[]         distinguishedName = new object[2];
                        distinguishedName[0] = aDGroupPartitionDNPair.Group.DistinguishedName;
                        distinguishedName[1] = runtimeException.Message;
                        string str4 = string.Format(CultureInfo.CurrentCulture, this._perGroupOperationFailedMessage, distinguishedName);
                        base.WriteWarning(str4);
                        DebugLogger.LogError("SetADPrincipalGroupMembership", str4);
                        aDGroups.Add(aDGroupPartitionDNPair.Group);
                    }
                }
                if (aDGroups.Count <= 0)
                {
                    if (this._cmdletParameters.GetSwitchParameterBooleanValue("PassThru"))
                    {
                        foreach (ADPrincipal aDPrincipal in this._validExtendedPrincipalList)
                        {
                            base.WriteObject(aDPrincipal);
                        }
                    }
                }
                else
                {
                    ADException aDException = new ADException(this._overallOperationFailedMessage);
                    base.ThrowTerminatingError(new ErrorRecord(aDException, "1", ErrorCategory.OperationStopped, aDGroups.ToArray()));
                }
                return(true);
            }
            else
            {
                DebugLogger.LogInfo("SetADPrincipalGroupMembership", "User selected NO when asked to confirm..exiting without doing anything.");
                return(false);
            }
        }