Sune
Sune

Reputation: 3280

Checking to see if a mailbox is on a specifc database (syntax error!)

I would like to check $true or $false if a user is in a specific mailboxdatabase. This doesn't work:

if((get-mailbox user| select Database) -eq "server\group\dbgroup") {
   echo $true
} else {
   echo $false
}

(returns False)

But

get-mailbox user | select Database    

returns

Database
--------
server\group\dbgroup

How do I check for this value?

Upvotes: 0

Views: 2089

Answers (2)

Shay Levy
Shay Levy

Reputation: 126902

@Christian already gave you the answer, but to answer you "syntax error". When you pipe to Select-Object you get back an object with the properties you specified: Database. To access the property you need to call it, so in order for your code to work you'd have to write it this way:

if((get-mailbox user| select Database).Database -eq "server\group\dbgroup") {
   echo $true
} else {
   echo $false
}

Upvotes: 1

CB.
CB.

Reputation: 60956

Try like this (can't test it):

if( (get-mailbox user).Database -eq "server\group\dbgroup")

Upvotes: 0

Related Questions