public ComputerInfoResult GetComputerInfo(Computer computer) { var powershell = new Powershell.Manager(""); var result = new OperationResult(); result = powershell.GetComputerBIOSInfo(ref computer); var response = new ComputerInfoResult(computer, result); return response; }
private void GetComputerInfo(object state) { var computer = new Computer(); SynchronizationContext uiContext = state as SynchronizationContext; var ps = new Cdw.Powershell.Manager(""); var result = ps.GetComputerBIOSInfo(ref computer); if (result.HasErrors()) { SetError(string.Concat(result.Errors.ToArray())); } result = ps.GetComputerNICInfo(ref computer); if (result.HasErrors()) { SetError(string.Concat(result.Errors.ToArray())); } result = ps.GetComputerSystemInfo(ref computer); if (result.HasErrors()) { SetError(string.Concat(result.Errors.ToArray())); } Program.Computer = computer; uiContext.Post(SwitchForms,null); }
public OperationResult GetComputerSystemInfo(ref Computer computer) { var Result = new OperationResult(); try { using (Runspace runspace = GetRunspace(ref Result)) { Pipeline pipeline = runspace.CreatePipeline(); Command getProcess = new Command("Get-WmiObject Win32_ComputerSystemProduct | Select Vendor,Version,Name,IdentifyingNumber,UUID", true); pipeline.Commands.Add(getProcess); System.Collections.ObjectModel.Collection<System.Management.Automation.PSObject> output = null; output = pipeline.Invoke(); if ((pipeline.Error != null) && pipeline.Error.Count > 0) { foreach (object Err in pipeline.Error.ReadToEnd()) { Result.Errors.Add(Err.ToString()); Result.Status = Statics.Result.Error; } } else { if (output.Count > 0) { computer.Manufacturer = output[0].Properties["Vendor"].Value.ToString(); computer.Model = output[0].Properties["Name"].Value.ToString(); computer.SerialNumber = output[0].Properties["IdentifyingNumber"].Value.ToString(); computer.BiosGuid = output[0].Properties["UUID"].Value.ToString(); Result.Status = Statics.Result.Success; } else { throw new Exception("No System information available"); } } } } catch (Exception ex) { Result.Status = Statics.Result.Error; Result.Errors.Add(ex.Message); Result.Errors.Add(ex.StackTrace); } return Result; }
public OperationResult GetComputerNICInfo(ref Computer computer) { var Result = new OperationResult(); try { using (Runspace runspace = GetRunspace(ref Result)) { Pipeline pipeline = runspace.CreatePipeline(); Command getProcess = new Command("Get-WmiObject win32_networkadapterConfiguration -Filter {IPEnabled=true} | Select IPAddress,MACAddress", true); pipeline.Commands.Add(getProcess); System.Collections.ObjectModel.Collection<System.Management.Automation.PSObject> output = null; output = pipeline.Invoke(); if ((pipeline.Error != null) && pipeline.Error.Count > 0) { foreach (object Err in pipeline.Error.ReadToEnd()) { Result.Errors.Add(Err.ToString()); Result.Status = Statics.Result.Error; } } else { if (output.Count > 0) { computer.MACAddress = output[0].Properties["MACAddress"].Value.ToString(); String[] addresses = (String[])output[0].Properties["IPAddress"].Value; computer.IPAddress = addresses[0]; Result.Status = Statics.Result.Success; } else { throw new Exception("No Network information available"); } } } } catch (Exception ex) { Result.Status = Statics.Result.Error; Result.Errors.Add(ex.Message); Result.Errors.Add(ex.StackTrace); } return Result; }
public OperationResult GetComputerBIOSInfo(ref Computer computer) { var Result = new OperationResult(); try { using (Runspace runspace = GetRunspace(ref Result)) { Pipeline pipeline = runspace.CreatePipeline(); Command getProcess = new Command("Get-WmiObject win32_bios | Select Manufacturer,Name,BIOSVersion,ReleaseDate,SMBIOSBIOSVersion", true); pipeline.Commands.Add(getProcess); System.Collections.ObjectModel.Collection<System.Management.Automation.PSObject> output = null; output = pipeline.Invoke(); if ((pipeline.Error != null) && pipeline.Error.Count > 0) { foreach (object Err in pipeline.Error.ReadToEnd()) { Result.Errors.Add(Err.ToString()); Result.Status = Statics.Result.Error; } } else { if (output.Count > 0) { computer.BiosVersion = output[0].Properties["SMBIOSBIOSVersion"].Value.ToString(); Result.Status = Statics.Result.Success; } else { throw new Exception("No BIOS information available"); } } } } catch (Exception ex) { Result.Status = Statics.Result.Error; Result.Errors.Add(ex.Message); Result.Errors.Add(ex.StackTrace); } return Result; }
public OperationResult GetComputer(string computername) { var Result = new OperationResult(); var comp = new Computer(); try { using (Runspace runspace = GetRunspace(ref Result)) { Pipeline pipeline = runspace.CreatePipeline(); InitializePS(ref Result, pipeline); if (Result.Status == Statics.Result.Error) { return Result; } pipeline = runspace.CreatePipeline(); Command getProcess = new Command("Get-ADComputer"); getProcess.Parameters.Add("Identity", computername); getProcess.Parameters.Add("Properties", "*"); pipeline.Commands.Add(getProcess); System.Collections.ObjectModel.Collection<System.Management.Automation.PSObject> output = null; output = pipeline.Invoke(); if ((pipeline.Error != null) && pipeline.Error.Count > 0) { foreach (object Err in pipeline.Error.ReadToEnd()) { if (Err.ToString().ToLower().Contains("cannot find an object with identity:")) { comp.Exists = false; Result.ResultAsComputer = comp; } else { Result.Errors.Add(Err.ToString()); Result.Status = Statics.Result.Error; } } } else { if (output.Count > 0) { comp.Name = output[0].Properties["Name"].Value.ToString(); comp.OrganizationalUnit = output[0].Properties["DistinguishedName"].Value.ToString().Replace("CN=" + computername + ",", ""); comp.Exists = true; Result.ResultAsComputer = comp; Result.Status = Statics.Result.Success; } else { comp.Exists = false; } } } } catch (Exception ex) { if (ex.Message.Contains("Cannot find an object with identity")) { // this is not an error Result.Messages.Add("No computer found !"); Result.Status = Statics.Result.Success; comp.Exists = false; Result.ResultAsComputer = comp; } else { Result.Errors.Add(ex.Message); Result.Errors.Add(ex.StackTrace); Result.Status = Statics.Result.Error; } } return Result; }
public AuthenticationRequest() { Computer = new Computer(); }
public ComputerInfoResult(Computer computer, OperationResult result) { Computer = computer; Result = result; }