Reputation: 1
I seem to be coming across issues with a check i have put in place to confirm a mailbox has ben converted from a users mailbox to shared mailbox.
Connect-ExchangeOnline -UserPrincipalName $UserCredential.UserName
Write-Host "checking mailbox has converted to a shared mailbox...."
$Mailboxcheck = Get-Mailbox "$username" | select isshared
if ($Mailboxcheck.IsShared -eq $False) {
[System.Windows.MessageBox]::Show("Mailbox for $($username) has NOT been converted to shared, please confirm.")
} else {
[System.Windows.MessageBox]::Show("Mailbox for $($username) has been converted to shared.")
}
the issue is sometimes this check will work and other times it won't (randomly). So we convert the mailbox to a shared mailbox via the above script then the check will sometimes come up as the $False message rather then the else message but when we go to manually check it after it's run the mailbox has been converted to shared.
The only things i can think of is to add the disconnect and reconnect to exchange online in case it's due to some syncing time, Possibly add a Start-sleep to the script to give it more time to sync, or its to do with the if statement and the variable $false as $mailboxcheck.isshared should only provide a value of "True" or "False"
if ($Mailboxcheck.IsShared -eq $False)
Another way i have made the script to check is with a switch statement but am unsure if that will be me any benefit and unsure if it's the right use case or should stick to the if statement
$Mailboxcheck = Get-Mailbox "$username" | select isshared
switch ($Mailboxcheck.isshared)
{
True {[System.Windows.MessageBox]::Show("Mailbox for $($username) has been converted to shared."); Break}
False {[System.Windows.MessageBox]::Show("Mailbox for $($username) has NOT been converted to shared, please confirm."); Break}
default {[System.Windows.MessageBox]::Show("Unable to check mailbox type for $($username). Please confirm it has been converted to shared.")}
}
Let me know your thoughts.
Upvotes: 0
Views: 120
Reputation: 349
Try running this code along side the other one to see when the IsShared property actually changes:
$repeat = $true
do
{
$Mailboxcheck = Get-Mailbox "$username"
Write-Host "Date = $(get-date)" -for Green
write-host "RecipientTypeDetails = $($Mailboxcheck.RecipientTypeDetails)" -ForegroundColor Cyan
write-host "IsShared = $($Mailboxcheck.isShared)" -ForegroundColor yellow
""
sleep 10
}
while ($repeat -eq $true)
Upvotes: 0