Example #1
0
		private List<string> SetUpComputerInfoUsingWsman(IEnumerable<string> computerNames, CancellationToken token)
		{
			bool flag = false;
			List<string> strs = new List<string>();
			CimOperationOptions cimOperationOption = new CimOperationOptions();
			cimOperationOption.Timeout = TimeSpan.FromMilliseconds(2000);
			cimOperationOption.CancellationToken = new CancellationToken?(token);
			CimOperationOptions cimOperationOption1 = cimOperationOption;
			foreach (string computerName in computerNames)
			{
				try
				{
					CimSession cimSession = RemoteDiscoveryHelper.CreateCimSession(computerName, this.Credential, this.WsmanAuthentication, token, this);
					using (cimSession)
					{
						IEnumerable<CimInstance> cimInstances = cimSession.QueryInstances("root/cimv2", "WQL", "Select * from Win32_OperatingSystem", cimOperationOption1);
						foreach (CimInstance cimInstance in cimInstances)
						{
							flag = true;
							if (this._computerInfos.ContainsKey(computerName))
							{
								continue;
							}
							RestartComputerCommand.ComputerInfo computerInfo = new RestartComputerCommand.ComputerInfo();
							computerInfo.LastBootUpTime = cimInstance.CimInstanceProperties["LastBootUpTime"].Value.ToString();
							computerInfo.RebootComplete = false;
							RestartComputerCommand.ComputerInfo computerInfo1 = computerInfo;
							this._computerInfos.Add(computerName, computerInfo1);
							strs.Add(computerName);
						}
						if (!flag)
						{
							string str = StringUtil.Format(ComputerResources.RestartComputerSkipped, computerName, ComputerResources.CannotGetOperatingSystemObject);
							ErrorRecord errorRecord = new ErrorRecord(new InvalidOperationException(str), "RestartComputerSkipped", ErrorCategory.OperationStopped, computerName);
							base.WriteError(errorRecord);
						}
					}
				}
				catch (CimException cimException1)
				{
					CimException cimException = cimException1;
					string str1 = StringUtil.Format(ComputerResources.RestartComputerSkipped, computerName, cimException.Message);
					ErrorRecord errorRecord1 = new ErrorRecord(new InvalidOperationException(str1), "RestartComputerSkipped", ErrorCategory.OperationStopped, computerName);
					base.WriteError(errorRecord1);
				}
				catch (Exception exception1)
				{
					Exception exception = exception1;
					CommandProcessorBase.CheckForSevereException(exception);
					string str2 = StringUtil.Format(ComputerResources.RestartComputerSkipped, computerName, exception.Message);
					ErrorRecord errorRecord2 = new ErrorRecord(new InvalidOperationException(str2), "RestartComputerSkipped", ErrorCategory.OperationStopped, computerName);
					base.WriteError(errorRecord2);
				}
			}
			return strs;
		}
Example #2
0
		private List<string> SetUpComputerInfoUsingDcom(IEnumerable<string> computerNames, ConnectionOptions options)
		{
			List<string> strs = new List<string>();
			ObjectQuery objectQuery = new ObjectQuery("Select * From Win32_OperatingSystem");
			EnumerationOptions enumerationOption = new EnumerationOptions();
			enumerationOption.UseAmendedQualifiers = true;
			enumerationOption.DirectRead = true;
			EnumerationOptions enumerationOption1 = enumerationOption;
			ManagementObjectSearcher managementObjectSearcher = null;
			ManagementObjectCollection managementObjectCollections = null;
			foreach (string computerName in computerNames)
			{
				try
				{
					try
					{
						ManagementScope managementScope = new ManagementScope(ComputerWMIHelper.GetScopeString(computerName, "\\root\\cimv2"), options);
						managementObjectSearcher = new ManagementObjectSearcher(managementScope, objectQuery, enumerationOption1);
						managementObjectCollections = managementObjectSearcher.Get();
						if (managementObjectCollections.Count <= 0)
						{
							string str = StringUtil.Format(ComputerResources.RestartComputerSkipped, computerName, ComputerResources.CannotGetOperatingSystemObject);
							ErrorRecord errorRecord = new ErrorRecord(new InvalidOperationException(str), "RestartComputerSkipped", ErrorCategory.OperationStopped, computerName);
							base.WriteError(errorRecord);
						}
						else
						{
							foreach (ManagementBaseObject managementBaseObject in managementObjectCollections)
							{
								if (this._computerInfos.ContainsKey(computerName))
								{
									continue;
								}
								RestartComputerCommand.ComputerInfo computerInfo = new RestartComputerCommand.ComputerInfo();
								computerInfo.LastBootUpTime = managementBaseObject.Properties["LastBootUpTime"].Value.ToString();
								computerInfo.RebootComplete = false;
								RestartComputerCommand.ComputerInfo computerInfo1 = computerInfo;
								this._computerInfos.Add(computerName, computerInfo1);
								strs.Add(computerName);
							}
						}
					}
					catch (ManagementException managementException1)
					{
						ManagementException managementException = managementException1;
						string str1 = StringUtil.Format(ComputerResources.RestartComputerSkipped, computerName, managementException.Message);
						ErrorRecord errorRecord1 = new ErrorRecord(new InvalidOperationException(str1), "RestartComputerSkipped", ErrorCategory.OperationStopped, computerName);
						base.WriteError(errorRecord1);
					}
					catch (COMException cOMException1)
					{
						COMException cOMException = cOMException1;
						string str2 = StringUtil.Format(ComputerResources.RestartComputerSkipped, computerName, cOMException.Message);
						ErrorRecord errorRecord2 = new ErrorRecord(new InvalidOperationException(str2), "RestartComputerSkipped", ErrorCategory.OperationStopped, computerName);
						base.WriteError(errorRecord2);
					}
					catch (UnauthorizedAccessException unauthorizedAccessException1)
					{
						UnauthorizedAccessException unauthorizedAccessException = unauthorizedAccessException1;
						string str3 = StringUtil.Format(ComputerResources.RestartComputerSkipped, computerName, unauthorizedAccessException.Message);
						ErrorRecord errorRecord3 = new ErrorRecord(new InvalidOperationException(str3), "RestartComputerSkipped", ErrorCategory.OperationStopped, computerName);
						base.WriteError(errorRecord3);
					}
				}
				finally
				{
					if (managementObjectSearcher != null)
					{
						managementObjectSearcher.Dispose();
					}
					if (managementObjectCollections != null)
					{
						managementObjectCollections.Dispose();
					}
				}
			}
			return strs;
		}