param( [string]$Identity ) try { # Import admin credentials $serverAddress = Get-Content -Path ".\DefaultServer.txt" $credential = Import-Clixml -Path ".\AdminCredential.xml" # Establish session with Exchange Server $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://$serverAddress/PowerShell/ -Authentication Kerberos -Credential $credential Import-PSSession $session -DisableNameChecking # Get the current AutoReply status $currentStatus = Get-MailboxAutoReplyConfiguration -Identity $Identity | Select-Object -ExpandProperty AutoReplyState # Determine the display color and status message if ($currentStatus -eq "Enabled") { $statusColor = "Green" $statusMessage = "enabled" } else { $statusColor = "Red" $statusMessage = "disabled" } Write-Host "AutoReply is currently $statusMessage for $Identity." -ForegroundColor $statusColor # Ask the user if they want to change the status $choice = Read-Host "Do you want to change this status? (yes/no)" if ($choice -eq "yes") { $newStatus = if ($currentStatus -eq "Enabled") { "Disabled" } else { "Enabled" } Set-MailboxAutoReplyConfiguration -Identity $Identity -AutoReplyState $newStatus -ExternalAudience All $newColor = if ($newStatus -eq "Enabled") { "Red" } else { "Green" } Write-Host "AutoReply is now $newStatus for $Identity." -ForegroundColor $newColor } else { Write-Host "No changes made." -ForegroundColor Cyan } Remove-PSSession $session } catch { Write-Host "Failed to retrieve or update AutoReply for $Identity. Error:" -ForegroundColor Red Write-Host $_ }