About get-object in EMS scripts
-
Friday, May 11, 2012 12:36 PM
Hi !
I watched a video tutorial about exchange management shell and wonderful scripts and i have a small simple question
This is a powershell command to create mailbox for all users in test OU
get-user -organizationalname test | where-object{$_.recipienttype -eq "user" -eq "User"| enable-mailbox -database Myexdatabase
but i can not understand this one !!
where-object{$_.recipienttype -eq "user"}
we said get users from that OU and enable mailbox for them, so what is this command !?look at these :
get-mailbox -organizationalunit test | set-mailbox prohibitsendquota 50MB
it just gets some users and set a quota for them ... there is no where-object here
and many other examples which are just a get and a set
- Edited by MohammadG Friday, May 11, 2012 2:38 PM
All Replies
-
Friday, May 11, 2012 7:21 PM
Hi
You don't need the where-object portion if all the objects in that OU are the users you want to enable. So if you have an OU called Test which only contains the user objects you want to create mailboxes for then you could run this command:
Get-User -OrganizationalUnit test | Enable-Mailbox
Note that you don't have to specify the database as one will be selected automatically.
Steve
-
Saturday, May 12, 2012 4:23 AM
Thanks Steve
As i am watching this video from Mr. Bruzzese (TrainSignal),
http://exclusivelyexchange.com/who-is-j-peter-bruzzese/
The Goal of this script is to create mailbox for all users in test OU, So if this
Get-User -OrganizationalUnit test | Enable-Mailbox
is enough, So can u tell me what is probably that where-object part ?
for example it is necessary if there are some groups in that OU ? Or ...
-
Saturday, May 12, 2012 5:06 AM
Hi,
Let's say that some of the users in the OU already has a mailbox, you would want to filter them out and using where-object {$_.recipienttype -eq "user"} would.
In other words, only the users without a mailbox in the OU TEST, would get a mailbox if the database Myexdatabase if you ran:
get-user -organizationalunit domain.local/test | where-object {$_.recipienttype -eq "user"}| enable-mailbox -database Myexdatabase
Martina Miskovic
- Edited by Martina_MiskovicMicrosoft Community Contributor Saturday, May 12, 2012 5:07 AM
- Edited by Martina_MiskovicMicrosoft Community Contributor Saturday, May 12, 2012 5:10 AM
-
Saturday, May 12, 2012 5:17 AM
Thanks Martina
Would you please explain a bit more
As i got you mean this where-object {$_.recipienttype -eq "user"} causes to exclude the users who already have mailbox
My questions is what is the syntax exactly. I can not figure out how this exclusion is related to and set using $_.recipienttype = User
is there a property named .recipienttype and it is equal to User for users who have mailboxes ?
and second one :
what happens if some users have mailbox there and we do not use where-object {$_.recipienttype -eq "user"}
Maybe we just get a warning that user has already a mailbox and script continues to other ones. Am i right ?
-
Saturday, May 12, 2012 5:20 AM
Did you notice the difference between
The command you posted: get-user -organizationalname test | where-object{$_.recipienttype -eq "user" -eq "User"| enable-mailbox -database Myexdatabase
...and mine:
get-user -organizationalunit domain.local/test | where-object {$_.recipienttype -eq "user"}| enable-mailbox -database MyexdatabaseThe one I posted has the correct syntax.
Edit: Yes you will get an error for the users that already has a mailbox.
Martina Miskovic
- Edited by Martina_MiskovicMicrosoft Community Contributor Saturday, May 12, 2012 5:22 AM Edit
-
Saturday, May 12, 2012 5:37 AM
sorry ! my bad ! I have an error in my command
get-user -organizationalname test | where-object{$_.recipienttype -eq "user" -eq "User"| enable-mailbox -database Myexdatabas
the eq "user" has been repeated
and also oranizationalunit is ok
and i think that domain.local/test is not necessary because the ou is just under domain tree (i tested that)
So the correct form is :
get-user -organizationalunit test | where-object {$_.recipienttype -eq "user"}| enable-mailbox -database Myexdatabase
so excuse me for my errors ( i was thinking deep about that get-obkect)
but beside these
i have not answer to my question yet
I can not figure out how this exclusion is related to and set using $_.recipienttype = User
is there a property named .recipienttype and it is equal to User for users who have mailboxes ?
thanks for your valuable time
-
Saturday, May 12, 2012 5:44 AM
Yes, all users has a recipienttype and one without a mailbox is of type "User" and a user that has a mailbox has the recipienttype "UserMailbox"
So if you run Get-User and see the recipienttype User, you can be sure that this user is not a recipient in Exchange.
Understanding Recipients
http://technet.microsoft.com/en-us/library/bb201680.aspxMartina Miskovic
- Marked As Answer by MohammadG Saturday, May 12, 2012 7:18 AM
-
Saturday, May 12, 2012 7:24 AM
Thank you very much
This sentence was exactly what i was looking for
Yes, all users has a recipienttype and one without a mailbox is of type "User" and a user that has a mailbox has the recipienttype "UserMailbox"
A property which is "User" for those who have not mailbox and "UserMailbox" for those who have
Thank you very much

