How to Export a List of Installed Updates to a File in Batch Script
Generating a documented record of all installed patches and security updates is a cornerstone of professional IT auditing and system maintenance. Whether you are preparing a compliance report for an organization or simply creating a backup "snapshot" of a system's state before a major software migration, being able to export this data automatically is a time-saving necessity.
This guide will teach you how to use Batch scripting to extract information about "Hotfixes" and save it into various file formats, including plain text, CSV, and HTML.
Why Export Update Lists?
- Auditing: Providing proof of security compliance to stakeholders.
- Troubleshooting: Enabling technicians to compare "Broken Machine A" with "Working Machine B."
- Change Management: Tracking which patches were applied between two points in time.
- Remote Access: Receiving a system's update status via email or a network log when you cannot access the GUI.
For most accurate results, especially when querying the system-wide update database, you should run your Batch script as an Administrator. This ensures the wmic and systeminfo utilities have full access to all system metadata.
Method 1: Exporting to Plain Text (Human-Readable)
The simplest way to export data is using the > redirection operator. This creates a file that is perfect for reading in Notepad.
@echo off
set "OUT_FILE=%userprofile%\Desktop\Updates_%COMPUTERNAME%.txt"
echo [PROCESS] Generating update list for %COMPUTERNAME%...
echo --- Windows Update Report --- > "%OUT_FILE%"
echo Generated on: %date% %time% >> "%OUT_FILE%"
echo ----------------------------- >> "%OUT_FILE%"
echo. >> "%OUT_FILE%"
:: Use wmic to append the list in table format
wmic qfe get HotFixID,Description,InstalledOn /format:table >> "%OUT_FILE%" 2>&1
:: Check if file exists and has meaningful content
for %%i in ("%OUT_FILE%") do (
if %%~zi lss 100 (
echo [ERROR] Export failed or returned an empty list.
pause
exit /b 1
)
)
echo [SUCCESS] Report saved to: %OUT_FILE%
pause
Method 2: Exporting to CSV (Excel Compatible)
For data analysis, the CSV (Comma Separated Values) format is much more powerful. You can import this file into Excel to sort by date or filter for specific KB numbers.
@echo off
set "CSV_FILE=%userprofile%\Desktop\UpdateAudit.csv"
echo [PROCESS] Exporting updates to CSV...
:: Using the /format:csv switch of wmic
:: The output includes a leading blank line; use "more +1" to strip it
wmic qfe get Caption,Description,HotFixID,InstalledOn /format:csv > "%CSV_FILE%" 2>&1
:: Remove blank lines that wmic inserts (common CSV cleanup)
set "CLEAN_FILE=%userprofile%\Desktop\UpdateAudit_clean.csv"
findstr /v /r "^$" "%CSV_FILE%" > "%CLEAN_FILE%"
move /y "%CLEAN_FILE%" "%CSV_FILE%" >nul
:: Verify output
for %%i in ("%CSV_FILE%") do (
if %%~zi lss 10 (
echo [ERROR] Export failed or returned an empty list.
pause
exit /b 1
)
)
echo [SUCCESS] CSV file created at: %CSV_FILE%
pause
Method 3: Exporting to HTML (Professional Reporting)
One of the most under-utilized features of the wmic command is its ability to build an HTML table automatically. This turns your raw data into a professional-looking web report.
@echo off
set "HTML_FILE=%userprofile%\Desktop\SystemUpdateSummary.html"
echo [PROCESS] Building HTML report...
:: Using the /format:htable switch
wmic qfe get HotFixID,Description,InstalledOn /format:htable > "%HTML_FILE%" 2>&1
:: Verify output
for %%i in ("%HTML_FILE%") do (
if %%~zi lss 100 (
echo [ERROR] Export failed or returned an empty list.
pause
exit /b 1
)
)
echo [SUCCESS] Open this file in your browser to view the report: %HTML_FILE%
pause
Common Pitfalls and How to Avoid Them
Permission Denied on Desktop
If you are running the script as a different user (e.g., using runas), %userprofile% might point to a folder you don't have permission to write to.
Wrong Way:
wmic qfe get HotFixID > %userprofile%\Desktop\output.txt
:: If %userprofile% is "Administrator" but you are "User", this fails.
Correct Way:
Either specify a neutral path like C:\Temp or ensure the script creates the directory first.
:: Create the output directory if it does not exist
if not exist "C:\Temp" mkdir "C:\Temp"
set "OUT_FILE=C:\Temp\Updates_%COMPUTERNAME%.txt"
wmic qfe get HotFixID,Description,InstalledOn /format:table > "%OUT_FILE%" 2>&1
Empty Files
If the WMI service is currently busy or corrupted, the resulting file might be empty (0 bytes).
Add a sanity check to your script. Verify the file size after export to ensure it actually contains data before telling the user it was successful.
:: Check if file exists and is not empty
for %%i in ("%OUT_FILE%") do (
if %%~zi lss 100 (
echo [ERROR] Export failed or returned an empty list.
) else (
echo [SUCCESS] Report saved successfully.
)
)
Best Practices for Enterprise Exporting
- Network Shares: If you are running this on 50 machines, have them save to a central location using the computer name in the filename:
set "LOG_PATH=\\Server\Audit\Updates_%COMPUTERNAME%.txt"wmic qfe get HotFixID,Description,InstalledOn /format:table > "%LOG_PATH%" 2>&1
- Date Formatting: For better sorting, use an ISO-style date format (YYYY-MM-DD) in your filename to keep logs organized:
:: Extract date components for ISO formattingset "STAMP=%date:~10,4%-%date:~4,2%-%date:~7,2%"set "OUT_FILE=C:\Temp\Updates_%COMPUTERNAME%_%STAMP%.txt"
- Combine with OS Info: A report is more useful if it also includes the Windows Version and Build Number:
echo. >> "%OUT_FILE%"echo --- System Information --- >> "%OUT_FILE%"systeminfo | findstr /B /C:"OS Name" /C:"OS Version" >> "%OUT_FILE%"
Be aware that updates that were manually hidden by the user using a troubleshooter tool will not appear in this list, as they are not currently "Installed."
Conclusion
Exporting a list of installed Windows updates via Batch script is a highly effective way to manage and document system health. By mastering different output formats, Text for quick reading, CSV for data analysis, and HTML for professional reporting, you can provide stakeholders with the exact information they need in the most useful format. This automation reduces human error, ensures consistency across multiple systems, and provides an invaluable historical record for any Windows deployment or maintenance cycle. Always ensure proper file permissions and path management to guarantee that your export scripts run reliably in any user environment.