Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Filename: py_get_windows_update_logs.py
- # Version: 1.0.0
- # Author: Jeoi Reqi
- """
- This script retrieves Windows Update logs and saves them to separate files: one containing verbose information saved on the desktop, and the other containing ETL (Event Trace Log) data saved in the current working directory.
- Requirements:
- - Python 3.x
- - PowerShell
- Usage:
- 1. Run the script using Python 3.x.
- 2. The script will execute PowerShell commands to retrieve Windows Update logs.
- 3. Verbose logs will be saved as 'windows_update_verbose.log' on the desktop.
- 4. ETL logs will be saved as 'windows_update_etl.log' in the current working directory.
- Functions:
- - main(): Executes the script, retrieves Windows Update logs, and saves them to separate files.
- - save_verbose_log(): Saves verbose logs to 'windows_update_verbose.log' on the desktop.
- - save_etl_log(): Saves ETL logs to 'windows_update_etl.log' in the current working directory.
- Additional Notes:
- - Running this script requires administrative privileges as it executes PowerShell commands.
- - Ensure that PowerShell is installed and accessible from the command line.
- - The script may take some time to complete, depending on the size of the Windows Update logs.
- """
- import subprocess
- import os
- # Define the path to save the ETL log in the current working directory
- etl_log_path = os.path.join(os.getcwd(), "windows_update_etl.log")
- # Inform the user about the logging process
- print("Creating Windows Update logs... ")
- print("-----------------------------------------------------")
- print("Creating Verbose log on the Desktop... ")
- print("Creating ETL log in the Current Working Directory... ")
- print("-----------------------------------------------------")
- print("This may take some time. Thank you for your patience.")
- print("-----------------------------------------------------")
- print()
- # Run the PowerShell cmdlet to get the Windows Update ETL logs and write directly to the ETL log file
- try:
- with open(etl_log_path, "w") as etl_file:
- subprocess.run(["powershell.exe", "-Command", "get-windowsUpdateLog"], stdout=etl_file, check=True)
- print(f"Windows Update ETL logs successfully retrieved and saved to: {etl_log_path}")
- except subprocess.CalledProcessError:
- print("Failed to retrieve Windows Update ETL logs.")
- # Prompt the user to hit enter to exit
- input("Press Enter to exit...")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement