Пример #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
        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);
        }
Пример #3
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);
        }