if/else finding mailboxes

Hi all,

im trying to write a script to check if a mailbox exists, if it does tell me its active, if its inactive, tell me its inactive and if it isnt found, tell me it isnt found.

i have this so far i have already logged in to exchange.

$whatmailbox = read-host -Prompt "enter email address to search"

$mbx = ""

$mbx = Get-Mailbox $whatmailbox

if ($mbx -eq $true)

{Write-Host "mailbox is active"}

elseif ($mbx -eq "")

{$mbx = Get-Mailbox $whatmailbox -inactivemailboxonly | write-host "mailbox found however it is inactive"}

else

{Write-Host "no mailbox found"}

Remove-PSSession $Session

Write-Host "Session closed"

i dont get errors but i do get mailboxes that i KNOW are active that return “no mailbox found”

im a bit lost

Thanks

submitted by /u/Cerveza87
[link] [comments]

Leave a Reply