Advertisement
Python253

bash_get_windows_update_logs

May 2nd, 2024
797
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.40 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Author: Jeoi Reqi
  4. # Filename: bash_get_windows_update_logs.sh
  5. # Version: 1.0.0
  6. #
  7. # Description:
  8. #   This script retrieves Windows Update logs and saves them to separate files:
  9. #   one containing verbose information saved on the desktop, and the other containing
  10. #   ETL (Event Trace Log) data saved in the current working directory.
  11. #
  12. # Requirements:
  13. #   - Python 3.x
  14. #   - PowerShell
  15. #
  16. # Usage:
  17. #   1. Run the script using Python 3.x.
  18. #   2. The script will execute PowerShell commands to retrieve Windows Update logs.
  19. #   3. Verbose logs will be saved as 'windows_update_verbose.log' on the desktop.
  20. #   4. ETL logs will be saved as 'windows_update_etl.log' in the current working directory.
  21. #
  22. # Functions:
  23. #   - main(): Executes the script, retrieves Windows Update logs, and saves them to separate files.
  24. #   - save_verbose_log(): Saves verbose logs to 'windows_update_verbose.log' on the desktop.
  25. #   - save_etl_log(): Saves ETL logs to 'windows_update_etl.log' in the current working directory.
  26. #
  27. # Additional Notes:
  28. #   - Running this script requires administrative privileges as it executes PowerShell commands.
  29. #   - Ensure that PowerShell is installed and accessible from the command line.
  30. #   - The script may take some time to complete, depending on the size of the Windows Update logs.
  31.  
  32. # Define the path to save the ETL log in the current working directory
  33. ETL_LOG_PATH="$(pwd)/windows_update_etl.log"
  34.  
  35. # Inform the user about the logging process
  36. echo "Creating Windows Update logs...                      "
  37. echo "-----------------------------------------------------"
  38. echo "Creating Verbose log on the Desktop...               "
  39. echo "Creating ETL log in the Current Working Directory... "
  40. echo "-----------------------------------------------------"
  41. echo "This may take some time. Thank you for your patience."
  42. echo "-----------------------------------------------------"
  43. echo
  44.  
  45. # Run the PowerShell cmdlet to get the Windows Update ETL logs and write directly to the ETL log file
  46. powershell.exe -Command "get-windowsUpdateLog" > "$ETL_LOG_PATH"
  47.  
  48. # Check if the PowerShell command executed successfully for the ETL log
  49. if [ $? -eq 0 ]; then
  50.     echo "Windows Update ETL logs successfully retrieved and saved to: $ETL_LOG_PATH"
  51. else
  52.     echo "Failed to retrieve Windows Update ETL logs."
  53. fi
  54.  
  55. # Prompt the user to hit enter to exit
  56. read -rp "Press Enter to exit..."
  57.  
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement