header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

If mailbox exists...
Last Post 08 Jun 2008 01:19 AM by mipbar. 5 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
mipbarUser is Offline
New Member
New Member
Posts:9

--
14 May 2008 06:59 PM  

 

Is there a clean way to test if a mailbox exists on an account without having to trap for the error from a failed "get-mailbox" command?

I'm starting to write a script that will check if a mailbox exists, disable it if it does, disable the account, and move the account to a specific OU.  A foreach ($user in $disableusers) kind of thing.

Thanks



KarlMitschkeUser is Offline
Basic Member
Basic Member
Posts:161

--
14 May 2008 07:47 PM  
Try this:

$usertest = get-user -Identity <USER ALIAS> |select RecipientType
if ($usertest.RecipientType -eq "userMailbox")
{
Do your tasks
}


KarlMitschkeUser is Offline
Basic Member
Basic Member
Posts:161

--
14 May 2008 08:06 PM  
Actually, incase you also have legacy mailboxes (pre 2007, or incorrectly configured AD objects that are mail enabled)


$usertest = get-user -Identity <USER ALIAS> |select RecipientType
if ($usertest.RecipientType -match "Mailbox")
{
Do your tasks
}


mipbarUser is Offline
New Member
New Member
Posts:9

--
14 May 2008 08:30 PM  

Excellent, I'll give it a shot.

Thanks



mdgrayUser is Offline
New Member
New Member
Posts:5

--
15 May 2008 05:56 AM  
Sounds like a great little script. Would you consider sharing when you are done?


mipbarUser is Offline
New Member
New Member
Posts:9

--
08 Jun 2008 01:19 AM  

absolutely, attached is what i ended up with.  it only accomplished exactly what i needed at the time, which was to read from an excel/csv file a list of samaccountnames, change the description of the user, move the user to a specific ou, disable the mailbox and disable the account.

it was by no means an automation attempt.  i ran one piece at a time by changing the 'choice' value.

you would need to put in your dc and domain info, and remove the -whatif's

Posted By mdgray on 05/14/2008 9:56 PM
Sounds like a great little script. Would you consider sharing when you are done?

 


Attachment: 167202087571.ps1

You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer