# Define the file paths $downloadsPath = [Environment]::GetFolderPath('MyDocuments') -replace 'Documents$', 'Downloads' $files = @( "$downloadsPath\Disabled_Users_last_3_Days.txt", "$downloadsPath\Disabled_Users_last_7_Days.txt", "$downloadsPath\Disabled_Users.txt", "$downloadsPath\Expired_Users.txt", "$downloadsPath\Expired_Users_Last_3_Days.txt", "$downloadsPath\Expired_Users_Last_7_Days.txt", "$downloadsPath\inactive_users_30_days.txt", "$downloadsPath\inactive_users_90_days.txt" ) # Loop through each file and generate individual HTML reports foreach ($file in $files) { if (Test-Path $file) { # Import the CSV file $users = Import-Csv -Path $file # Check which column exists and dynamically set the header $dateColumn = if ($users[0].PSObject.Properties['DisabledDate']) { 'DisabledDate' } elseif ($users[0].PSObject.Properties['ExpirationDate']) { 'ExpirationDate' } elseif ($users[0].PSObject.Properties['LastLogonDate']) { 'LastLogonDate' } else { 'N/A' } # Create the HTML report $reportName = [System.IO.Path]::GetFileNameWithoutExtension($file) + ".html" $htmlFilePath = "$downloadsPath\$reportName" $htmlContent = @"
| Name | SamAccountName | EmailAddress | $dateColumn | FormattedOU |
|---|---|---|---|---|
| $($_.Name) | $($_.SamAccountName) | $($_.EmailAddress) | $dateValue | $($_.FormattedOU) |