Beispiel #1
0
        protected override void ProcessRecord()
        {
            string    hostName  = Dns.GetHostName();
            string    str       = null;
            Exception exception = null;

            if (base.ShouldProcess(hostName))
            {
                try
                {
                    ManagementObject managementObject = new ManagementObject(string.Concat("Win32_ComputerSystem.Name=\"", hostName, "\""));
                    if (!(bool)managementObject["PartOfDomain"])
                    {
                        string      resetComputerNotInDomain = ComputerResources.ResetComputerNotInDomain;
                        ErrorRecord errorRecord = new ErrorRecord(new InvalidOperationException(resetComputerNotInDomain), "ComputerNotInDomain", ErrorCategory.InvalidOperation, hostName);
                        base.ThrowTerminatingError(errorRecord);
                    }
                    str = (string)LanguagePrimitives.ConvertTo(managementObject["Domain"], typeof(string), CultureInfo.InvariantCulture);
                }
                catch (ManagementException managementException1)
                {
                    ManagementException managementException = managementException1;
                    exception = managementException;
                }
                catch (COMException cOMException1)
                {
                    COMException cOMException = cOMException1;
                    exception = cOMException;
                }
                catch (UnauthorizedAccessException unauthorizedAccessException1)
                {
                    UnauthorizedAccessException unauthorizedAccessException = unauthorizedAccessException1;
                    exception = unauthorizedAccessException;
                }
                if (exception != null)
                {
                    string      str1         = StringUtil.Format(ComputerResources.FailToGetDomainInformation, exception.Message);
                    ErrorRecord errorRecord1 = new ErrorRecord(new InvalidOperationException(str1), "FailToGetDomainInformation", ErrorCategory.OperationStopped, hostName);
                    base.ThrowTerminatingError(errorRecord1);
                }
                ResetComputerMachinePasswordCommand.ResetMachineAccountPassword(str, hostName, this.Server, this.Credential, this);
                return;
            }
            else
            {
                return;
            }
        }
Beispiel #2
0
        protected override void ProcessRecord()
        {
            bool      flag;
            string    str;
            string    str1;
            string    str2;
            string    hostName  = Dns.GetHostName();
            string    str3      = null;
            Exception exception = null;

            if (base.ShouldProcess(hostName))
            {
                try
                {
                    ManagementObject managementObject = new ManagementObject(string.Concat("Win32_ComputerSystem.Name=\"", hostName, "\""));
                    if (!(bool)managementObject["PartOfDomain"])
                    {
                        string      testComputerNotInDomain = ComputerResources.TestComputerNotInDomain;
                        ErrorRecord errorRecord             = new ErrorRecord(new InvalidOperationException(testComputerNotInDomain), "ComputerNotInDomain", ErrorCategory.InvalidOperation, hostName);
                        base.ThrowTerminatingError(errorRecord);
                    }
                    str3 = (string)LanguagePrimitives.ConvertTo(managementObject["Domain"], typeof(string), CultureInfo.InvariantCulture);
                }
                catch (ManagementException managementException1)
                {
                    ManagementException managementException = managementException1;
                    exception = managementException;
                }
                catch (COMException cOMException1)
                {
                    COMException cOMException = cOMException1;
                    exception = cOMException;
                }
                catch (UnauthorizedAccessException unauthorizedAccessException1)
                {
                    UnauthorizedAccessException unauthorizedAccessException = unauthorizedAccessException1;
                    exception = unauthorizedAccessException;
                }
                if (exception != null)
                {
                    string      str4         = StringUtil.Format(ComputerResources.FailToGetDomainInformation, exception.Message);
                    ErrorRecord errorRecord1 = new ErrorRecord(new InvalidOperationException(str4), "FailToGetDomainInformation", ErrorCategory.OperationStopped, hostName);
                    base.ThrowTerminatingError(errorRecord1);
                }
                if (!this.Repair)
                {
                    flag = this.VerifySecureChannel(str3, hostName);
                    if (flag)
                    {
                        str1 = StringUtil.Format(ComputerResources.SecureChannelAlive, str3);
                    }
                    else
                    {
                        str1 = StringUtil.Format(ComputerResources.SecureChannelBroken, str3);
                    }
                    str = str1;
                }
                else
                {
                    ResetComputerMachinePasswordCommand.ResetMachineAccountPassword(str3, hostName, this.Server, this.Credential, this);
                    flag = this.ResetSecureChannel(str3);
                    if (flag)
                    {
                        str2 = StringUtil.Format(ComputerResources.RepairSecureChannelSucceed, str3);
                    }
                    else
                    {
                        str2 = StringUtil.Format(ComputerResources.RepairSecureChannelFail, str3);
                    }
                    str = str2;
                }
                base.WriteObject(flag);
                base.WriteVerbose(str);
                return;
            }
            else
            {
                return;
            }
        }