예제 #1
0
        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);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Retrieve a computer by his name in the Wsus Server
        /// </summary>
        /// <param name="computerName">Name of the computer to retrieve.</param>
        /// <returns>An instance of IComputerTarget or null if the computer has not been found.</returns>
        private IComputerTarget GetComputerTargetByName(string computerName)
        {
            IComputerTarget computer = null;

            try
            {
                computer = this._updateServer.GetComputerTargetByName(computerName);
            }
            catch (Exception) { }

            return(computer);
        }
예제 #3
0
        private Dictionary <string, string> GetComputerTargetStatus(IUpdateServer wsus, string id)
        {
            Dictionary <string, string> retDict = new Dictionary <string, string>();
            IComputerTarget             target  = wsus.GetComputerTarget(id);
            IUpdateSummary summary = target.GetUpdateInstallationSummary();

            retDict.Add("InstalledCount", summary.InstalledCount.ToString());
            retDict.Add("DownloadedCount", summary.DownloadedCount.ToString());
            retDict.Add("FailedCount", summary.FailedCount.ToString());
            retDict.Add("InstalledPendingRebootCount", summary.InstalledPendingRebootCount.ToString());
            retDict.Add("IsSummedAcrossAllUpdates", summary.IsSummedAcrossAllUpdates.ToString());
            retDict.Add("LastUpdated", summary.LastUpdated.ToString());
            retDict.Add("NotApplicableCount", summary.NotApplicableCount.ToString());
            retDict.Add("UnknownCount", summary.UnknownCount.ToString());
            retDict.Add("NotInstalledCount", summary.NotInstalledCount.ToString());
            return(retDict);
        }
예제 #4
0
        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);
        }
예제 #5
0
            public ComputerDetail this[IComputerTarget computer]
            {
                get
                {
                    // Loop through all computers, looking for one that matches
                    foreach (ComputerDetail t in this.List)
                    {
                        // They match if both the fulldomain name *and* SUS ID match
                        if (computer.FullDomainName == t.Name && computer.Id == t.SusID)
                        {
                            // Got one - return it
                            return(t);
                        }
                    }

                    // Didn't find one - return a null
                    return(null);
                }
            }
예제 #6
0
        public bool ComputerInIgnoredGroup(IComputerTarget c)
        {
            foreach (IComputerTargetGroup g in c.GetComputerTargetGroups())
            {
                // Is this group in the list of ignored computer groups?
                if (IgnoreComputerGroupCollection.Keys.ToArray().Contains(g.Id))
                    // Yes
                    return true;
            }

            // Computer is not in any of the ignored computer groups.
            return false;
        }
예제 #7
0
 public ComputerDetail(IComputerTarget computer)
 {
     Computer = computer;
 }
예제 #8
0
 public int Add(IComputerTarget add)
 {
     return this.List.Add(new ComputerDetail(add));
 }
예제 #9
0
            public ComputerDetail this[IComputerTarget computer]
            {
                get
                {
                    // Loop through all computers, looking for one that matches
                    foreach (ComputerDetail t in this.List)
                    {
                        // They match if both the fulldomain name *and* SUS ID match
                        if (computer.FullDomainName == t.Name && computer.Id == t.SusID)
                            // Got one - return it
                            return t;
                    }

                    // Didn't find one - return a null
                    return null;
                }
            }
예제 #10
0
 internal FrmEventDisplayer(UpdateEventCollection eventCollection, IComputerTarget computer)
 {
     InitializeComponent();
     _eventCollection = eventCollection;
     _computer        = computer;
 }
예제 #11
0
 public epRowData(string fault, IComputerTarget c)
 {
     Fault = fault;
     EndpointName = c.FullDomainName;
     ipAddress = c.IPAddress;
     LastContact = c.LastReportedStatusTime;
     LastStatus = c.LastSyncResult;
     UpstreamServer = c;
 }
예제 #12
0
 public int Add(IComputerTarget add)
 {
     return(this.List.Add(new ComputerDetail(add)));
 }
예제 #13
0
 public ComputerDetail(IComputerTarget computer)
 {
     Computer = computer;
 }