public WSUS() { // I use impersonation to use other logon than mine. Remove the following "using" if not needed using (Impersonation.LogonUser("mydomain.local", "admin_account_wsus", "Password", LogonType.Batch)) { ComputerTargetScope scope = new ComputerTargetScope(); IUpdateServer server = AdminProxy.GetUpdateServer("wsus_server.mydomain.local", false, 80); ComputerTargetCollection targets = server.GetComputerTargets(scope); // Search targets = server.SearchComputerTargets("any_server_name_or_ip"); // To get only on server FindTarget method IComputerTarget target = FindTarget(targets, "any_server_name_or_ip"); Console.WriteLine(target.FullDomainName); IUpdateSummary summary = target.GetUpdateInstallationSummary(); UpdateScope _updateScope = new UpdateScope(); // See in UpdateInstallationStates all other properties criteria _updateScope.IncludedInstallationStates = UpdateInstallationStates.Downloaded; UpdateInstallationInfoCollection updatesInfo = target.GetUpdateInstallationInfoPerUpdate(_updateScope); int updateCount = updatesInfo.Count; foreach (IUpdateInstallationInfo updateInfo in updatesInfo) { Console.WriteLine(updateInfo.GetUpdate().Title); } } }
public static IComputerTarget FindTarget(ComputerTargetCollection coll, string computername) { foreach (IComputerTarget target in coll) { if (target.FullDomainName.Contains(computername.ToLower())) { return(target); } } return(null); }
public static List <string> GetWSUSlist(params string[] list) { List <string> result = new List <string>(200); //не забудь изменить количество string namehost = list[0]; //имя Пк, на котором будем искать string = "example1"; string servername = list[1]; //имя сервера string = "WIN-E1U41FA6E55"; string Username = list[2]; string Password = list[3]; try { ComputerTargetScope scope = new ComputerTargetScope(); IUpdateServer server = AdminProxy.GetUpdateServer(servername, false, 8530); ComputerTargetCollection targets = server.GetComputerTargets(scope); // Search targets = server.SearchComputerTargets(namehost); // To get only on server FindTarget method IComputerTarget target = FindTarget(targets, namehost); result.Add("Имя ПК: " + target.FullDomainName); IUpdateSummary summary = target.GetUpdateInstallationSummary(); UpdateScope _updateScope = new UpdateScope(); // See in UpdateInstallationStates all other properties criteria //_updateScope.IncludedInstallationStates = UpdateInstallationStates.Downloaded; UpdateInstallationInfoCollection updatesInfo = target.GetUpdateInstallationInfoPerUpdate(_updateScope); int updateCount = updatesInfo.Count; result.Add("Кол -во найденных обновлений - " + updateCount); foreach (IUpdateInstallationInfo updateInfo in updatesInfo) { result.Add(updateInfo.GetUpdate().Title); } } catch (Exception ex) { result.Add("Что-то пошло не так: " + ex.Message); } return(result); }
private List <Dictionary <string, string> > GetComputerTargetGroup(IUpdateServer wsus, string id) { List <Dictionary <string, string> > retList = new List <Dictionary <string, string> >(); IComputerTargetGroup group = wsus.GetComputerTargetGroup(new Guid(id)); ComputerTargetCollection members = group.GetComputerTargets(); foreach (IComputerTarget member in members) { Dictionary <string, string> details = new Dictionary <string, string>(); details.Add("Id", member.Id); details.Add("Name", member.FullDomainName); details.Add("Ip", member.IPAddress.ToString()); details.Add("LastReport", member.LastReportedInventoryTime.ToString()); details.Add("ComputerRole", member.ComputerRole.ToString()); retList.Add(details); } return(retList); }
public frmSUSWatch() { InitializeComponent(); wsus = cfg.wsus; // Populate duplicated SUS ID grid from XML foreach (string susid in cfg.DefaultSusIDCollection) { DataGridViewRow r = grdSUSID.Rows[grdSUSID.Rows.Add()]; r.Cells[susID.Index].Value = susid; r.Cells[susSource.Index].Value = "Previously Saved"; } // Refresh display this.Refresh(); // Get list of current computers ComputerTargetScope s = new ComputerTargetScope(); s.IncludeDownstreamComputerTargets = true; ComputerTargetCollection cc = wsus.server.GetComputerTargets(s); // Add all existing computers to our array int count = 0; foreach (IComputerTarget c in cc) { ctc.Add(c); count++; } Log("Added " + count.ToString() + " computers already in database"); }
private void tim_Tick(object sender, EventArgs e) { // If it's not time, decrement the progress bar and exit if (prg.Value > prg.Minimum) { prg.Value--; return; } // Time to update SUS IDs prg.Value = prg.Maximum; // Refresh display this.Refresh(); // Get list of current computers ComputerTargetScope s = new ComputerTargetScope(); s.IncludeDownstreamComputerTargets = true; ComputerTargetCollection cc = wsus.server.GetComputerTargets(s); // Loop through all computers to see if we already know about them foreach (IComputerTarget t in cc) { // Try to find a known computer ComputerDetail d = ctc[t]; if (d == null) { // We got a new one! ctc.Add(t); int count = ctc.SusIDCount(t.Id); Log("New computer found - " + t.FullDomainName + " (ID " + t.Id + ") " + count.ToString() + " of this ID found."); // Do we have a SUS ID we've seen associated with another PC? if (count > 1) { // Yes! Add it to the data grid, or update the existing entry DataGridViewRow r = null; foreach (DataGridViewRow gr in grdSUSID.Rows) { if (gr.Cells[susID.Index].Value.ToString() == t.Id) { // Found an existing entry - note it and break r = gr; break; } } // Did we find a row, or do we need to add one? if (r == null) { // We need to add one grdSUSID.Rows.Insert(0, 1); } r = grdSUSID.Rows[0]; r.Cells[susID.Index].Value = t.Id; r.Cells[susCount.Index].Value = count.ToString(); r.Cells[susSource.Index].Value = "Detected"; } } } }