Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Rugby-Ball/56bb2fd9d2e207b810038ac80fc1e835 to your computer and use it in GitHub Desktop.

Select an option

Save Rugby-Ball/56bb2fd9d2e207b810038ac80fc1e835 to your computer and use it in GitHub Desktop.
This will pull a list of installed patches using Get-Hotfix cmdlt for a list of servers. And export out to an Excel file. Requires the Module ImportExcel to be installed and imported. #Utility #Public #Inventory #Security #Audit #Windows #Patching
# Get-hotfix-installed-for-list-of-servers.ps1
<#
Description: This will pull a list of installed patches using Get-Hotfix cmdlt for a list of servers. And export out to an Excel file.
Requires the Module ImportExcel to be installed and imported.
Written: Ed Walsh
PowerShell.Core tested: Yes
MS-Graph: No
Version: 1.0.0
Create Date: 3/19/2024
Revised Date: 3/19/2024
#>
### Install Module if you do not already have it installed. Only needs to be done once.
# Install-Module -Name ImportExcel -Scope CurrentUser
# Import the required module
Import-Module ImportExcel
# Enter in server names to check
$servers = @('Server1', 'Server2') # replace with appropriate server names
# Make sure the c:\Temp folder exists if not, then create it.
If(-not(Test-Path -Path "c:\temp"))
{New-Item -ItemType Directory -Force -Path C:\temp}
# Create an empty array to hold the results
$results = @()
# Get the current date and time
$date = Get-Date -Format 'MM/dd/yyyy hh:mm tt (UTC zz)'
# Loop through each server
foreach ($server in $servers) {
# Get the hotfixes
$hotfixes = Get-HotFix -ComputerName $server | sort InstalledOn -Descending
# Loop through each hotfix
foreach ($hotfix in $hotfixes) {
# Create a custom object for each hotfix
$findings = New-Object PSObject -Property ( [Ordered]@{ "Server" = $server ;
"HotFixID" = $hotfix.HotFixID ;
"Description" = $hotfix.Description ;
"InstalledOn" = $hotfix.InstalledOn
} )
# Add the findings to the results array
$results += $findings } }
# Export the results to an Excel file. You need the Module IMPORTEXCEL installed and Imported.
$results | Export-Excel -Path "C:\temp\Installed-Patches-$(get-date -f yyyMMdd-hhmm).xlsx" -Title "Run-On Date: $date" -AutoSize -FreezeTopRow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment