private bool SetADDCPrpProcessCSRoutine()
        {
            this._identityDCObj = this._cmdletParameters["Identity"] as ADDomainController;
            this.SetPipelinedSessionInfo(this._identityDCObj.SessionInfo);
            CmdletSessionInfo cmdletSessionInfo = this.GetCmdletSessionInfo();
            ADDomainControllerFactory <ADDomainController> aDDomainControllerFactory = new ADDomainControllerFactory <ADDomainController>();

            aDDomainControllerFactory.SetCmdletSessionInfo(cmdletSessionInfo);
            ADObject      directoryObjectFromIdentity = aDDomainControllerFactory.GetDirectoryObjectFromIdentity(this._identityDCObj, cmdletSessionInfo.DefaultPartitionPath);
            StringBuilder stringBuilder = new StringBuilder("Set-ADObject -identity $args[0] ");

            if (this._operationType != SetADDCPasswordReplicationPolicyOperationType.AddPasswordReplicationPolicy)
            {
                if (this._operationType == SetADDCPasswordReplicationPolicyOperationType.RemovePasswordReplicationPolicy)
                {
                    stringBuilder.Append(" -Remove ");
                }
            }
            else
            {
                stringBuilder.Append(" -Add ");
            }
            stringBuilder.Append(" $args[1] ");
            if (base.ShouldProcessOverride(directoryObjectFromIdentity.IdentifyingString))
            {
                try
                {
                    object[] objArray = new object[2];
                    objArray[0] = directoryObjectFromIdentity;
                    objArray[1] = this._principalsToAddOrRemove;
                    base.InvokeCommand.InvokeScript(stringBuilder.ToString(), false, PipelineResultTypes.Output, null, objArray);
                }
                catch (RuntimeException runtimeException1)
                {
                    RuntimeException runtimeException = runtimeException1;
                    object[]         message          = new object[1];
                    message[0] = runtimeException.Message;
                    string str = string.Format(CultureInfo.CurrentCulture, "Failed adding or removing the password-replication-policy:  {0}", message);
                    DebugLogger.LogError("SetADDCPasswordReplicationPolicy", str);
                    base.WriteError(new ErrorRecord(runtimeException, "0", ErrorCategory.WriteError, this._identityDCObj));
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #2
0
        private bool GetADAcctResPrpProcessCSRoutine()
        {
            ADResultantPasswordReplicationPolicy aDResultantPasswordReplicationPolicy = ADResultantPasswordReplicationPolicy.DenyExplicit;
            int?value;

            this._partitionPath     = this._cmdletParameters["Partition"] as string;
            this._identityADAccount = this._cmdletParameters["Identity"] as ADAccount;
            this._targetDCAccount   = this._cmdletParameters["DomainController"] as ADDomainController;
            base.SetPipelinedSessionInfo(this._identityADAccount.SessionInfo);
            CmdletSessionInfo cmdletSessionInfo = base.GetCmdletSessionInfo();

            if (cmdletSessionInfo.ADRootDSE.IsWindows2008AndAbove())
            {
                if (!cmdletSessionInfo.ADRootDSE.IsWritable())
                {
                    object[] dNSHostName = new object[1];
                    dNSHostName[0] = cmdletSessionInfo.ADRootDSE.DNSHostName;
                    base.WriteWarning(string.Format(CultureInfo.CurrentCulture, StringResources.WarningResultantPRPNotAccurateOnRODC, dNSHostName));
                }
                ADDomainControllerFactory <ADDomainController> aDDomainControllerFactory = new ADDomainControllerFactory <ADDomainController>();
                aDDomainControllerFactory.SetCmdletSessionInfo(cmdletSessionInfo);
                ADAccountFactory <ADAccount> aDAccountFactory = new ADAccountFactory <ADAccount>();
                aDAccountFactory.SetCmdletSessionInfo(cmdletSessionInfo);
                ADObject         directoryObjectFromIdentity = aDDomainControllerFactory.GetDirectoryObjectFromIdentity(this._targetDCAccount, cmdletSessionInfo.DefaultPartitionPath);
                ADObject         aDObject          = aDAccountFactory.GetDirectoryObjectFromIdentity(this._identityADAccount, cmdletSessionInfo.DefaultPartitionPath);
                ADObjectSearcher distinguishedName = SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, directoryObjectFromIdentity.DistinguishedName, ADSearchScope.Base);
                using (distinguishedName)
                {
                    distinguishedName.Filter = ADOPathUtil.CreateFilterClause(ADOperator.Like, "objectClass", "*");
                    distinguishedName.Properties.Add("msDS-IsUserCachableAtRodc");
                    distinguishedName.InputDN = aDObject.DistinguishedName;
                    ADObject aDObject1 = distinguishedName.FindOne();
                    if (aDObject1["msDS-IsUserCachableAtRodc"] == null)
                    {
                        int?nullable = null;
                        value = nullable;
                    }
                    else
                    {
                        value = (int?)aDObject1["msDS-IsUserCachableAtRodc"].Value;
                    }
                    int?nullable1 = value;
                    if (nullable1.HasValue)
                    {
                        if (!Utils.TryParseEnum <ADResultantPasswordReplicationPolicy>(nullable1.ToString(), out aDResultantPasswordReplicationPolicy))
                        {
                            DebugLogger.LogInfo("GetADAccountResultantPasswordReplicationPolicy", string.Format("Error parsing resultant prp: {0} for account {1} on RODC {2}", aDResultantPasswordReplicationPolicy, aDObject.DistinguishedName, directoryObjectFromIdentity.DistinguishedName));
                            base.WriteObject(ADResultantPasswordReplicationPolicy.Unknown);
                        }
                        else
                        {
                            base.WriteObject(aDResultantPasswordReplicationPolicy);
                        }
                    }
                    else
                    {
                        base.WriteObject(ADResultantPasswordReplicationPolicy.Unknown);
                    }
                }
                return(true);
            }
            else
            {
                base.WriteError(new ErrorRecord(new ArgumentException(StringResources.ErrorResultantPRPSpecifyWindows2008OrAbove), "GetADAccountResultantPasswordReplicationPolicy:ProcessRecord", ErrorCategory.InvalidData, null));
                return(false);
            }
        }