protected override void ProcessRecord() { string hostName; ConnectionOptions connection = ComputerWMIHelper.GetConnection(this.Authentication, this.Impersonation, this.Credential); object[] objArray = new object[2]; objArray[0] = 1; objArray[1] = 0; object[] objArray1 = objArray; if (this._force.IsPresent) { objArray1[0] = 5; } if (!this._asjob.IsPresent) { string empty = string.Empty; string[] strArrays = this._computername; for (int i = 0; i < (int)strArrays.Length; i++) { string str = strArrays[i]; if (str.Equals("localhost", StringComparison.CurrentCultureIgnoreCase) || str.Equals(".", StringComparison.OrdinalIgnoreCase)) { hostName = Dns.GetHostName(); empty = "localhost"; } else { hostName = str; } if (base.ShouldProcess(StringUtil.Format(ComputerResources.DoubleComputerName, empty, hostName))) { try { ManagementScope managementScope = new ManagementScope(ComputerWMIHelper.GetScopeString(str, "\\root\\cimv2"), connection); EnumerationOptions enumerationOption = new EnumerationOptions(); enumerationOption.UseAmendedQualifiers = true; enumerationOption.DirectRead = true; ObjectQuery objectQuery = new ObjectQuery("select * from Win32_OperatingSystem"); this.searcher = new ManagementObjectSearcher(managementScope, objectQuery, enumerationOption); foreach (ManagementObject managementObject in this.searcher.Get()) { object obj = managementObject.InvokeMethod("Win32shutdown", objArray1); int num = Convert.ToInt32(obj.ToString(), CultureInfo.CurrentCulture); if (num == 0) { continue; } ComputerWMIHelper.WriteNonTerminatingError(num, this, hostName); } } catch (ManagementException managementException1) { ManagementException managementException = managementException1; ErrorRecord errorRecord = new ErrorRecord(managementException, "StopComputerException", ErrorCategory.InvalidOperation, hostName); base.WriteError(errorRecord); } catch (COMException cOMException1) { COMException cOMException = cOMException1; ErrorRecord errorRecord1 = new ErrorRecord(cOMException, "StopComputerException", ErrorCategory.InvalidOperation, hostName); base.WriteError(errorRecord1); } } } return; } else { string machineNames = ComputerWMIHelper.GetMachineNames(this.ComputerName); if (base.ShouldProcess(machineNames)) { InvokeWmiMethod invokeWmiMethod = new InvokeWmiMethod(); invokeWmiMethod.Path = "Win32_OperatingSystem=@"; invokeWmiMethod.ComputerName = this._computername; invokeWmiMethod.Authentication = this._authentication; invokeWmiMethod.Impersonation = this._impersonation; invokeWmiMethod.Credential = this._credential; invokeWmiMethod.ThrottleLimit = this._throttlelimit; invokeWmiMethod.Name = "Win32Shutdown"; invokeWmiMethod.EnableAllPrivileges = SwitchParameter.Present; invokeWmiMethod.ArgumentList = objArray1; PSWmiJob pSWmiJob = new PSWmiJob(invokeWmiMethod, this._computername, this._throttlelimit, Job.GetCommandTextFromInvocationInfo(base.MyInvocation)); base.JobRepository.Add(pSWmiJob); base.WriteObject(pSWmiJob); return; } else { return; } } }
protected override void ProcessRecord() { ConnectionOptions connection = ComputerWMIHelper.GetConnection(this.Authentication, this.Impersonation, this.Credential); if (!this.asjob) { int num = 0; string[] strArrays = this.source; for (int i = 0; i < (int)strArrays.Length; i++) { string str = strArrays[i]; try { num++; string str1 = this.QueryString(this.destination, true, true); ObjectQuery objectQuery = new ObjectQuery(str1); ManagementScope managementScope = new ManagementScope(ComputerWMIHelper.GetScopeString(str, "\\root\\cimv2"), connection); managementScope.Options.EnablePrivileges = true; managementScope.Connect(); EnumerationOptions enumerationOption = new EnumerationOptions(); enumerationOption.UseAmendedQualifiers = true; enumerationOption.DirectRead = true; this.searcher = new ManagementObjectSearcher(managementScope, objectQuery, enumerationOption); for (int j = 0; j <= this.count - 1; j++) { ManagementObjectCollection managementObjectCollections = this.searcher.Get(); int num1 = 0; foreach (ManagementBaseObject managementBaseObject in managementObjectCollections) { num1++; this.ProcessPingStatus(managementBaseObject); if (num1 >= managementObjectCollections.Count && j >= this.count - 1 && num >= (int)this.Source.Length) { continue; } Thread.Sleep(this.delay * 0x3e8); } } } catch (ManagementException managementException1) { ManagementException managementException = managementException1; ErrorRecord errorRecord = new ErrorRecord(managementException, "TestConnectionException", ErrorCategory.InvalidOperation, null); base.WriteError(errorRecord); } catch (COMException cOMException1) { COMException cOMException = cOMException1; ErrorRecord errorRecord1 = new ErrorRecord(cOMException, "TestConnectionException", ErrorCategory.InvalidOperation, null); base.WriteError(errorRecord1); } } } else { string str2 = this.QueryString(this.destination, true, false); GetWmiObjectCommand getWmiObjectCommand = new GetWmiObjectCommand(); getWmiObjectCommand.Filter = str2.ToString(); getWmiObjectCommand.Class = "Win32_PingStatus"; getWmiObjectCommand.ComputerName = this.source; getWmiObjectCommand.Authentication = this.Authentication; getWmiObjectCommand.Impersonation = this.Impersonation; getWmiObjectCommand.ThrottleLimit = this.throttlelimit; PSWmiJob pSWmiJob = new PSWmiJob(getWmiObjectCommand, this.source, this.throttlelimit, base.MyInvocation.MyCommand.Name, this.count); base.JobRepository.Add(pSWmiJob); base.WriteObject(pSWmiJob); } if (this.quiet) { string[] strArrays1 = this.destination; for (int k = 0; k < (int)strArrays1.Length; k++) { string str3 = strArrays1[k]; bool flag = false; this.quietResults.TryGetValue(str3, out flag); base.WriteObject(flag); } } }
protected override void BeginProcessing() { if (!ComputerWMIHelper.SkipSystemRestoreOperationForARMPlatform(this)) { try { ConnectionOptions connection = ComputerWMIHelper.GetConnection(AuthenticationLevel.Packet, ImpersonationLevel.Impersonate, null); ManagementPath managementPath = new ManagementPath(); managementPath.Path = "\\root\\default"; ManagementScope managementScope = new ManagementScope(managementPath, connection); managementScope.Connect(); this.WMIClass = new ManagementClass("SystemRestore"); this.WMIClass.Scope = managementScope; ObjectQuery objectQuery = new ObjectQuery(string.Concat("select * from SystemRestore where SequenceNumber = ", this._restorepoint)); ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(managementScope, objectQuery); if (managementObjectSearcher.Get().Count != 0) { string machineName = Environment.MachineName; if (base.ShouldProcess(machineName)) { object[] objArray = new object[1]; objArray[0] = this._restorepoint; object[] objArray1 = objArray; this.WMIClass.InvokeMethod("Restore", objArray1); managementPath.Path = "\\root\\cimv2"; managementScope.Path = managementPath; ManagementClass managementClass = new ManagementClass("Win32_OperatingSystem"); managementClass.Scope = managementScope; ObjectQuery objectQuery1 = new ObjectQuery("Select * from Win32_OperatingSystem"); ManagementObjectSearcher managementObjectSearcher1 = new ManagementObjectSearcher(managementScope, objectQuery1); foreach (ManagementObject managementObject in managementObjectSearcher1.Get()) { string[] strArrays = new string[1]; strArrays[0] = ""; string[] strArrays1 = strArrays; managementObject.InvokeMethod("Reboot", strArrays1); } } } else { string str = StringUtil.Format(ComputerResources.InvalidRestorePoint, this._restorepoint); ArgumentException argumentException = new ArgumentException(str); ErrorRecord errorRecord = new ErrorRecord(argumentException, "InvalidRestorePoint", ErrorCategory.InvalidArgument, null); base.WriteError(errorRecord); } } catch (ManagementException managementException1) { ManagementException managementException = managementException1; if (managementException.ErrorCode.ToString().Equals("NotFound") || managementException.ErrorCode.ToString().Equals("InvalidClass")) { Exception exception = new ArgumentException(StringUtil.Format(ComputerResources.NotSupported, new object[0])); base.WriteError(new ErrorRecord(exception, "RestoreComputerNotSupported", ErrorCategory.InvalidOperation, null)); } else { ErrorRecord errorRecord1 = new ErrorRecord(managementException, "GetWMIManagementException", ErrorCategory.InvalidOperation, null); base.WriteError(errorRecord1); } } catch (COMException cOMException1) { COMException cOMException = cOMException1; if (!string.IsNullOrEmpty(cOMException.Message)) { ErrorRecord errorRecord2 = new ErrorRecord(cOMException, "COMException", ErrorCategory.InvalidOperation, null); base.WriteError(errorRecord2); } else { Exception argumentException1 = new ArgumentException(StringUtil.Format(ComputerResources.SystemRestoreServiceDisabled, new object[0])); base.WriteError(new ErrorRecord(argumentException1, "ServiceDisabled", ErrorCategory.InvalidOperation, null)); } } return; } else { return; } }
protected override void BeginProcessing() { bool flag = false; string[] strArrays = this._computername; for (int i = 0; i < (int)strArrays.Length; i++) { string str = strArrays[i]; StringBuilder stringBuilder = new StringBuilder(); ConnectionOptions connection = ComputerWMIHelper.GetConnection(AuthenticationLevel.Packet, ImpersonationLevel.Impersonate, this.Credential); ManagementScope managementScope = new ManagementScope(ComputerWMIHelper.GetScopeString(str, "\\root\\cimv2"), connection); managementScope.Connect(); if (this._id == null) { stringBuilder.Append("Select * from Win32_QuickFixEngineering"); flag = true; } else { stringBuilder.Append("Select * from Win32_QuickFixEngineering where ("); for (int j = 0; j <= (int)this._id.Length - 1; j++) { stringBuilder.Append("HotFixID= '"); stringBuilder.Append(this._id[j].ToString().Replace("'", "\\'")); stringBuilder.Append("'"); if (j < (int)this._id.Length - 1) { stringBuilder.Append(" Or "); } } stringBuilder.Append(")"); } this.searchProcess = new ManagementObjectSearcher(managementScope, new ObjectQuery(stringBuilder.ToString())); foreach (ManagementObject managementObject in this.searchProcess.Get()) { if (this._description == null) { this.inputContainsWildcard = true; } else { if (!this.FilterMatch(managementObject)) { continue; } } string item = (string)managementObject["InstalledBy"]; if (!string.IsNullOrEmpty(item)) { try { SecurityIdentifier securityIdentifier = new SecurityIdentifier(item); managementObject["InstalledBy"] = securityIdentifier.Translate(typeof(NTAccount)); } catch (IdentityNotMappedException identityNotMappedException) { } catch (SystemException systemException1) { SystemException systemException = systemException1; CommandsCommon.CheckForSevereException(this, systemException); } } base.WriteObject(managementObject); flag = true; } if (!flag && !this.inputContainsWildcard) { Exception argumentException = new ArgumentException(StringUtil.Format(HotFixResources.NoEntriesFound, str)); base.WriteError(new ErrorRecord(argumentException, "GetHotFixNoEntriesFound", ErrorCategory.ObjectNotFound, null)); } if (this.searchProcess != null) { this.Dispose(); } } }