and more in a single search tool across platforms. Read the announcement here. |
02/05/2024 02:23 AM
Hi All,
We create remote mailbox for any user at exchange level using PowerShell script. Currently only one server is added for that, but we want do add multiple server as backup.
So even if one server fails, PowerShell script should pick other server and should not disturb the mailbox creation.
I am not aware where can we add this configuration in script.
Thanks
shwet
02/05/2024 07:47 PM
# Array of Exchange servers
$exchangeServers = @("Server1", "Server2", "Server3")
# Mailbox creation parameters
$userName = "user1"
# Add other mailbox creation parameters as needed
foreach ($exchangeServer in $exchangeServers) {
try {
# Attempt to create the mailbox on the current server
$result = New-RemoteMailbox -UserPrincipalName "$userName@domain.com" -RemoteRoutingAddress "$userName@contoso.mail.onmicrosoft.com" -OnPremisesOrganizationalUnit "OU=Users,DC=domain,DC=com" -DomainController $exchangeServer -ErrorAction Stop
# If successful, break out of the loop
Write-Host "Mailbox created successfully on $exchangeServer"
break
} catch {
# Handle the error (optional)
Write-Host "Error creating mailbox on $exchangeServer: $_"
}
}
# Add additional logic here if needed after the loop