1

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 (<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:

Scan machine for installed hotfixes, compare that list to available fixes on server, install anything that is missing, reboot

And here is the mess that I've worked out so far:

List all installed hotfixes, but only pull the column that has the KB#. Put into text file.

$installedHotFixes = Get-HotFix | Select-Object HotFixID
$installedHotFixes > installedHF.txt

Search patcher server for msu files, recursive, since they're just thrown into a directory...for years. Put into a text file.

$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 > allHFs.txt

Get KB names for all HFs (this might be unnecessary if I can do the next thing)

$allHFs | Select-String -Pattern "kb\d*" | Select-Object { $_.Matches } > patch_kb_only.txt

search $allHFs for contents of $installedHotFixes, delete any line that matches, export non-matches to text. I don't think this works.

Foreach($item in $installedHotFixes
{
$allHFs | Select-String -Pattern "$item" | Select-Object { $_.Matches } > patch_kb_only.txt
}

compare above list to list of all hotfixes available on \patch, delete duplicates, output to new list

$installList = Get-Content 'installedHF.txt','allHFs.txt' | Group-Object | where-Object {$_.count -eq 1} | Foreach-object {$_.group[0]} | Set-Content 'install_these_hf2.txt'

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!

0 Answers0