Powershell Script to Find the Hotfixes Installed and its Details on the Server

PowerShell script to find the hotfix installed and its details on the server:

The report will have the below contents:

    1. Current SharePoint build versions.
    2. Hot Fix ID.
    3. Who installed the hot fix?
    4. When was the hot fix installed?

Edit the script to pass on the server names, from, to and SMTP address to send an email on the hotfix report. Download the attached file to get the .css file for the report.  
  1. $LogTime = Get-Date -Format yyyy-MM-dd_hh-mm  
  2. $LogFile = ".\HotFixReportPatch-$LogTime.rtf"  
  3.  
  4. # Add SharePoint PowerShell Snapin  
  5.   
  6.   
  7. if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) {  
  8.     Add-PSSnapin Microsoft.SharePoint.Powershell  
  9. }  
  10.   
  11. $scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent  
  12. Set-Location $scriptBase  
  13.  
  14.  
  15. #Deleting any .rtf files in the scriptbase location  
  16. $FindRTFFile = Get-ChildItem $scriptBase\*.* -include *.rtf  
  17. if($FindRTFFile)  
  18. {  
  19.   foreach($file in $FindRTFFile)  
  20.   {  
  21.    remove-item $file  
  22.   }  
  23. }  
  24.   
  25.   
  26. start-transcript $logfile  
  27.  
  28. #Get All the Servers where you need to find the hot fix report  
  29. #$Servers = @("server1" , "server2")  
  30. $Servers = @("Server names")  
  31.  
  32. #Get the hot-fix in a variable for desired output  
  33. $HotFixDetails = Get-HotFix -ComputerName $servers | Select CSName , HotFixID , InstalledOn , InstalledBy , Caption , Description | ConvertTo-Html -Fragment  
  34. ConvertTo-Html -Body "$HotFixDetails" -CssUri $scriptbase\style.CSS | Out-File $scriptbase\HotFix.html  
  35. write-host "The output is in the location $scriptbase\HotFix.html" -fore green  
  36.  
  37.  
  38. #Send Mail  
  39. $SMTP = "Your SMTP Server Name"  
  40. $From = "From Adddress"  
  41. $To = "To Adddress"  
  42.   
  43. Send-MailMessage -SmtpServer $SMTP  -From $From -To $To -Subject "SharePoint Hot Fix Installation Report" -Attachments $scriptbase\HotFix.html   
  44. write-host "Email with hotfix informations sent to $To" -fore cyan