×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Text
Posted by: Clifton Foster
Added: Jun 1, 2016 9:01 PM
Views: 15
Tags: no tags
A Powershell command to search for a list of installed hotfixes on a list of computers. hotfixes.txt and computers.txt are plain text files with one entry per line.
  1. # Set the current directory variable to the script root
  2. $currentDirectory=$PSScriptRoot
  3.  
  4. # Load the content of the two text files
  5. $hotfixes=Get-Content $currentDirectory\hotfixes.txt
  6. $computers=Get-Content $currentDirectory\computers.txt
  7.  
  8. # For each hotfix in the file hotfixes.txt
  9. foreach($hotfix in $hotfixes){
  10.  
  11. # Write to console and then to output.txt
  12. Write-Host "$hotfix" -foregroundcolor Yellow
  13. Add-Content $currentDirectory\output.txt "$hotfix`n"
  14. Write-Host "----------------------------------------------------" -foregroundcolor Magenta
  15. Add-Content $currentDirectory\output.txt "----------------------------------------------------`n"
  16.  
  17.     #For each computer in computers.txt  
  18.     foreach($computer in $computers) {
  19.         # If the hotfix is found on the computer
  20.             if (Get-WmiObject -Computer $computer -Class Win32_QuickFixEngineering -Filter "HotFixID='$hotfix'" -erroraction silentlycontinue)
  21.             {
  22.         Write-Host "$computer has $hotfix installed" -foregroundcolor green
  23.         Add-Content $currentDirectory\output.txt "$computer has $hotfix installed`n"
  24.         }
  25.             else
  26.             {
  27.         Write-Host "$computer does not have $hotfix installed (or failed to connect)" -foregroundcolor Red
  28.         Add-Content $currentDirectory\output.txt "$computer does not have $hotfix installed (or failed to connect)`n"
  29.         }
  30.     }
  31.     Write-Host "----------------------------------------------------" -foregroundcolor Magenta
  32.     Add-Content $currentDirectory\output.txt "----------------------------------------------------`n"
  33.     Write-Host ""
  34.     Add-Content $currentDirectory\output.txt "`n"
  35. }