title: Network install hotfixes with Powershell
body: <p>I might be complicating this. In fact, I guranteed that the way I'm trying to do this is probably terrible. I have a few machines (&lt;30) that are sort in disarray, hotfix-wise. I have a central server that holds all the *.msu files. I can't configure WSUS. I would like to do the following:</p>
  
  <p>Scan machine for installed hotfixes, compare that list to available fixes on server, install anything that is missing, reboot</p>
  
  <p>And here is the mess that I've worked out so far:</p>
  
  <p>List all installed hotfixes, but only pull the column that has the KB#. Put into text file.</p>
  
  <pre><code>$installedHotFixes = Get-HotFix | Select-Object HotFixID
  $installedHotFixes &gt; installedHF.txt
  </code></pre>
  
  <p>Search patcher server for msu files, recursive, since they're just thrown into a directory...for years. Put into a text file.</p>
  
  <pre><code>$dir = (Get-Item -Path "\\patches\patch" -Verbose).FullName
  $allHFs = Foreach($item in (Get-ChildItem -Recurse \\patches\patch *.msu -Name))
  {
  $item = $dir + "\" + $item
  echo $item
  }
  $allHFs &gt; allHFs.txt
  </code></pre>
  
  <p>Get KB names for all HFs (this might be unnecessary if I can do the next thing)</p>
  
  <pre><code>$allHFs | Select-String -Pattern "kb\d*" | Select-Object { $_.Matches } &gt; patch_kb_only.txt
  </code></pre>
  
  <p>search $allHFs for contents of $installedHotFixes, delete any line that matches, export non-matches to text. I don't think this works.</p>
  
  <pre><code>Foreach($item in $installedHotFixes
  {
  $allHFs | Select-String -Pattern "$item" | Select-Object { $_.Matches } &gt; patch_kb_only.txt
  }
  </code></pre>
  
  <p>compare above list to list of all hotfixes available on \patch, delete duplicates, output to new list</p>
  
  <pre><code>$installList = Get-Content 'installedHF.txt','allHFs.txt' | Group-Object | where-Object {$_.count -eq 1} | Foreach-object {$_.group[0]} | Set-Content 'install_these_hf2.txt'
  </code></pre>
  
  <p>And that's about where I got off work for a few days and sort of forgot what the hell I was doing. I was outputting things into a text file because that's the only way I could think to compare list contents, as I'm not great with PowerShell and it's capabilities (obviously). Is there a better way to do this? Thanks in advance!</p>