title: How to Discover if Windows Update is optional, recommended, or important
body: <p>I'm currently writing a type of automated program that among other things searches for windows updates.  It can search for and retrieve updates just fine, but I am having trouble drilling down for what priority an update is.  I would like to have an output similar to:</p>
  
  <p>Total Updates: 25
  Important: 12
  Optional: 13</p>
  
  <p>The .IsMandatory field is only used when the update is specifically for WUA itself, so important updates are not necessary labeled with .IsMandatory.</p>
  
  <p>Code snippet for searching the WUA is below:</p>
  
  <pre><code>Dim updateSession  ' Object to hold our MS Update Session
  Dim updateSearcher ' Object to perform our MS Win Update Search
  Dim results        ' Object to hold our MS Win Update Search Results
  Dim stopWatch As New Stopwatch()
  stopWatch.Start()
  
  outputWriter.WriteLine("----WINDOWS UPDATES-----@ " &amp; Now, False)
  outputWriter.WriteLine("  -We are beginning our update search. Please note, this may take a few minutes." &amp; _
                         "  On Windows Server 2003 this may take 800 years.", False)
  
  ' We cannot guarantee the update check will succeed, so use a try catch in case of error.
  Try
      updateSession = CreateObject("Microsoft.Update.Session")
      updateSearcher = updateSession.CreateUpdateSearcher()
      results = updateSearcher.Search("IsInstalled=0 and Type='Software' and IsHidden=0")
  Catch ex As Exception
      outputWriter.WriteLine("  ERROR: Something went wrong in our update search. Details below...", False)
      outputWriter.WriteLine("  Error Msg: " &amp; ex.Message, False)
      Return 1
   End Try
  
  Dim imp_updates = 0
  Dim opt_updates = 0
  For i = 0 To results.Updates.Count - 1
      Dim update = results.Updates.Item(i)
      If update.IsMandatory = False Then 
          opt_updates = opt_updates + 1
      Else
          imp_updates = imp_updates + 1
      End If
   Next
  
   outputWriter.WriteLine("Important Updates: " &amp; imp_updates, True)
   outputWriter.WriteLine("Optional Updates:  " &amp; opt_updates, True)
  </code></pre>