param( [string]$Identity ) try { # Get the user running the script $currentUser = $env:USERNAME $currentDomain = ([System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()).Name # Define the admin credentials and connect to Exchange $serverAddress = Get-Content -Path ".\DefaultServer.txt" $credential = Import-Clixml -Path ".\AdminCredential.xml" $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://$serverAddress/PowerShell/ -Authentication Kerberos -Credential $credential Import-PSSession $session -DisableNameChecking Write-Host "Assigning FullAccess permissions for $currentUser to $Identity..." -ForegroundColor Yellow # Assign FullAccess permission Add-MailboxPermission -Identity $Identity -User $currentUser -AccessRights FullAccess -InheritanceType All -Confirm:$false # Launch the logged-in user's OWA page to refresh their session Write-Host "Refreshing the logged-in user's webmail..." -ForegroundColor Yellow # Construct the base OWA URL for the logged-in user $loggedInUserMailboxUrl = "https://$serverAddress/owa/$currentUser@$currentDomain" # Open the logged-in user's OWA page in the browser Start-Process $loggedInUserMailboxUrl Write-Host "Webmail for $currentUser launched successfully." -ForegroundColor Green # Prompt the user to sign in before proceeding Read-Host "Please sign into your webmail and press Enter to continue" # Construct the mailbox URL for the target identity Write-Host "Opening the mailbox for ${Identity} and displaying its link..." -ForegroundColor Yellow $baseUrl = "https://$serverAddress/owa/" $mailboxUrl = "$baseUrl$Identity@$currentDomain/?offline=disabled" # Open the mailbox in the browser Start-Process $mailboxUrl # Output the URL to the console Write-Host "Access the additional mailbox using the following link:" -ForegroundColor Green Write-Host $mailboxUrl -ForegroundColor Cyan # Wait for user confirmation before revoking permissions Read-Host "Press Enter after you have finished using the mailbox" Write-Host "Removing FullAccess permissions for $currentUser from $Identity..." -ForegroundColor Yellow # Remove FullAccess permission Remove-MailboxPermission -Identity $Identity -User $currentUser -AccessRights FullAccess -InheritanceType All -Confirm:$false Write-Host "Permissions removed successfully." -ForegroundColor Green # Close the session Remove-PSSession $session } catch { Write-Host "An error occurred. Error details:" -ForegroundColor Red Write-Host $_ }