Created
March 19, 2024 21:34
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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