================================================================================
DEPLOYMENT LOGGING DOCUMENTATION
================================================================================

All deployment activity is automatically logged to:
  S:\DT\ADATA\SCRIPT\DEPLOY\LOGS\

Log files are named: HOSTNAME-YYYYMMDD-HHMMSS.txt

================================================================================
LOG FILE NAMING
================================================================================

Format: HOSTNAME-YYYYMMDD-HHMMSS.txt

Examples:
  G1JJVH63ESF-20251017-143022.txt
  G1JJXH63ESF-20251017-143155.txt
  G1JKYH63ESF-20251017-143301.txt

Components:
  - HOSTNAME: Computer name (from %COMPUTERNAME%)
  - YYYYMMDD: Date (Year, Month, Day)
  - HHMMSS: Time (Hour, Minute, Second)

================================================================================
WHAT IS LOGGED
================================================================================

Each log file contains:
  - Deployment start time
  - Hostname and system information
  - Administrator privilege check
  - Certificate import status
  - WinRM HTTPS listener creation
  - Firewall rule configuration
  - All success and error messages
  - Final deployment status (SUCCESS or FAILED)

================================================================================
LOG LOCATION
================================================================================

Network Path: S:\DT\ADATA\SCRIPT\DEPLOY\LOGS\

The batch file automatically:
  - Creates the log directory if it doesn't exist
  - Creates a new log file for each deployment
  - Logs all output (success and errors)
  - Shows log file location on screen

================================================================================
VIEWING LOGS
================================================================================

Method 1: Manual Browse
  1. Open Windows Explorer
  2. Navigate to: S:\DT\ADATA\SCRIPT\DEPLOY\LOGS\
  3. Open log files with Notepad

Method 2: PowerShell Script (Recommended)
  .\View-DeploymentLogs.ps1

  Available options:
    - List all logs
    - Show latest logs
    - Search by hostname
    - Filter by success/failure
    - Generate summary report

Method 3: Command Line
  # View latest log
  Get-Content S:\DT\ADATA\SCRIPT\DEPLOY\LOGS\*.txt | Select-Object -Last 50

  # Search for errors
  Get-ChildItem S:\DT\ADATA\SCRIPT\DEPLOY\LOGS\*.txt |
    Select-String "ERROR|FAIL"

  # List logs for specific PC
  Get-ChildItem S:\DT\ADATA\SCRIPT\DEPLOY\LOGS\G1JJVH63ESF-*.txt

================================================================================
LOG FILE EXAMPLE
================================================================================

G1JJVH63ESF-20251017-143022.txt:

============================================================================
WinRM HTTPS Deployment Log
============================================================================
Hostname: G1JJVH63ESF
Date/Time: 10/17/2025 14:30:22
Log File: S:\DT\ADATA\SCRIPT\DEPLOY\LOGS\G1JJVH63ESF-20251017-143022.txt
============================================================================

[OK] Running with Administrator privileges
Script directory: \\SERVER\WinRM-HTTPS\
[OK] Required files found
Executing WinRM HTTPS setup...

=== WinRM HTTPS Setup Script ===
Date: 10/17/2025 14:30:23
Logging to: S:\DT\ADATA\SCRIPT\DEPLOY\LOGS\G1JJVH63ESF-20251017-143022.txt

=== Importing Certificate ===
Importing certificate from: \\SERVER\WinRM-HTTPS\wildcard-logon-ds-ge-com-20251017.pfx
[OK] Certificate imported successfully
    Subject: CN=*.logon.ds.ge.com
    Thumbprint: C1412765B2839E9081FCEA77BB1E6D8840203509
    Expiration: 10/17/2027 08:16:34

=== Creating WinRM HTTPS Listener ===
Hostname: g1jjvh63esf.logon.ds.ge.com
Port: 5986
[OK] HTTPS listener created successfully

=== Configuring Windows Firewall ===
Creating firewall rule for port 5986...
[OK] Firewall rule created

============================================================================
[SUCCESS] WinRM HTTPS Setup Complete
============================================================================

================================================================================
TROUBLESHOOTING WITH LOGS
================================================================================

To find failed deployments:
  .\View-DeploymentLogs.ps1 -Failed

To check specific PC:
  .\View-DeploymentLogs.ps1 -Hostname "G1JJVH63ESF"

To see recent activity:
  .\View-DeploymentLogs.ps1 -Latest 10

To generate deployment report:
  .\View-DeploymentLogs.ps1
  (Select option 6: Generate summary report)

================================================================================
LOG RETENTION
================================================================================

Recommendation:
  - Keep logs for 90 days minimum
  - Archive older logs to backup location
  - Review logs periodically for issues

Log Management:
  # Delete logs older than 90 days
  Get-ChildItem S:\DT\ADATA\SCRIPT\DEPLOY\LOGS\*.txt |
    Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-90)} |
    Remove-Item

  # Archive old logs
  $archiveDate = (Get-Date).AddDays(-30)
  $logs = Get-ChildItem S:\DT\ADATA\SCRIPT\DEPLOY\LOGS\*.txt |
    Where-Object {$_.LastWriteTime -lt $archiveDate}

  Compress-Archive -Path $logs -DestinationPath "S:\DT\ADATA\SCRIPT\DEPLOY\ARCHIVE\logs-$(Get-Date -Format 'yyyyMM').zip"

================================================================================
BENEFITS OF LOGGING
================================================================================

1. Troubleshooting
   - See exactly what happened during deployment
   - Identify error patterns
   - Debug certificate or network issues

2. Tracking
   - Know which PCs have been deployed
   - See deployment timestamps
   - Track multiple deployment attempts

3. Compliance
   - Audit trail of all deployments
   - Document when/who deployed
   - Compliance with IT policies

4. Reporting
   - Generate deployment statistics
   - Identify problem PCs
   - Calculate success rates

================================================================================
INTEGRATION WITH OTHER SYSTEMS
================================================================================

Logs can be:
  - Imported into SIEM systems
  - Parsed for monitoring dashboards
  - Analyzed for trends
  - Used for automated alerting

Example: Send email alert on failure
  $failed = Get-ChildItem S:\DT\ADATA\SCRIPT\DEPLOY\LOGS\*.txt |
    Select-String "FAILED" | Select-Object -Last 1

  if ($failed) {
    Send-MailMessage -To "it@example.com" -Subject "Deployment Failed" -Body $failed
  }

================================================================================
