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 visibility status $currentStatus = Get-Mailbox -Identity $Identity | Select-Object -ExpandProperty HiddenFromAddressListsEnabled $color = if ($currentStatus) { "Red" } else { "Green" } $visibility = if ($currentStatus) { "hidden" } else { "visible" } Write-Host "User $Identity is currently $visibility in Exchange address lists." -ForegroundColor $color # Ask for action $choice = Read-Host "Do you want to change this status? (yes/no)" if ($choice -eq "yes") { $newStatus = -not $currentStatus $newColor = if ($newStatus) { "Red" } else { "Green" } Set-Mailbox -Identity $Identity -HiddenFromAddressListsEnabled $newStatus $updatedVisibility = if ($newStatus) { "hidden" } else { "visible" } Write-Host "User $Identity is now $updatedVisibility in Exchange address lists." -ForegroundColor $newColor } else { Write-Host "No changes made." -ForegroundColor Cyan } Remove-PSSession $session } catch { Write-Host "Failed to retrieve or update visibility for $Identity. Error:" -ForegroundColor Red Write-Host $_ }