Example #1
0
        internal static void WsusCheckWsus()
        {
            UpdateSearcher usearcher = new UpdateSearcher();

            var search = usearcher.Search("IsInstalled=0 and IsHidden=0");

            if (search.Updates.Count > 0)
            {
                Program.LogInfo($"There are updates available for installation");
                WsusDownloadFromWsus(search);
            }
            else
            {
                Program.LogInfo($"There are no updates available for installation");
            }
        }
Example #2
0
        public static UpdateCollection InsallWsusUpdates()
        {
            //var sSecurePassword = ConvertTo-SecureString –String sPassword –AsPlainText -Force
            //  var oCredential = CreateObject("System.Management.Automation.PSCredential") ' - ArgumentList sUser, sSecurePassword
            var sDateAndTime  = DateTime.Now;
            var sCriteria     = "IsInstalled=0 and Type='Software'";
            var oSearcher     = new UpdateSearcher();
            var oSearchResult = oSearcher.Search(sCriteria).Updates;
            var count         = oSearchResult.Count;
            var oSession      = new UpdateSession();
            var oDownloader   = oSession.CreateUpdateDownloader();

            oDownloader.Updates = oSearchResult;
            oDownloader.Download();
            var oInstaller = new UpdateInstaller();

            oInstaller.Updates = oSearchResult;
            //Result -> 2 = Succeeded, 3 = Succeeded with Errors, 4 = Failed, 5 = Aborted
            return((UpdateCollection)oInstaller.Install());
        }
 public void Invoke(ISearchJob searchJob, ISearchCompletedCallbackArgs callbackArgs)
 {
     Job          = searchJob;
     SearchResult = UpdateSearcher.EndSearch(searchJob);
 }