Advertisement
Python253

py_get_windows_update_logs

May 2nd, 2024
805
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.45 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Filename: py_get_windows_update_logs.py
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. 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.
  9.  
  10. Requirements:
  11. - Python 3.x
  12. - PowerShell
  13.  
  14. Usage:
  15. 1. Run the script using Python 3.x.
  16. 2. The script will execute PowerShell commands to retrieve Windows Update logs.
  17. 3. Verbose logs will be saved as 'windows_update_verbose.log' on the desktop.
  18. 4. ETL logs will be saved as 'windows_update_etl.log' in the current working directory.
  19.  
  20. Functions:
  21. - main(): Executes the script, retrieves Windows Update logs, and saves them to separate files.
  22. - save_verbose_log(): Saves verbose logs to 'windows_update_verbose.log' on the desktop.
  23. - save_etl_log(): Saves ETL logs to 'windows_update_etl.log' in the current working directory.
  24.  
  25. Additional Notes:
  26. - Running this script requires administrative privileges as it executes PowerShell commands.
  27. - Ensure that PowerShell is installed and accessible from the command line.
  28. - The script may take some time to complete, depending on the size of the Windows Update logs.
  29. """
  30.  
  31. import subprocess
  32. import os
  33.  
  34. # Define the path to save the ETL log in the current working directory
  35. etl_log_path = os.path.join(os.getcwd(), "windows_update_etl.log")
  36.  
  37. # Inform the user about the logging process
  38. print("Creating Windows Update logs...                      ")
  39. print("-----------------------------------------------------")
  40. print("Creating Verbose log on the Desktop...               ")
  41. print("Creating ETL log in the Current Working Directory... ")
  42. print("-----------------------------------------------------")
  43. print("This may take some time. Thank you for your patience.")
  44. print("-----------------------------------------------------")
  45. print()
  46.  
  47. # Run the PowerShell cmdlet to get the Windows Update ETL logs and write directly to the ETL log file
  48. try:
  49.     with open(etl_log_path, "w") as etl_file:
  50.         subprocess.run(["powershell.exe", "-Command", "get-windowsUpdateLog"], stdout=etl_file, check=True)
  51.     print(f"Windows Update ETL logs successfully retrieved and saved to: {etl_log_path}")
  52. except subprocess.CalledProcessError:
  53.     print("Failed to retrieve Windows Update ETL logs.")
  54.  
  55. # Prompt the user to hit enter to exit
  56. input("Press Enter to exit...")
  57.  
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement