Powershell - Get-mailbox what's wrong in this statement?

$Item.Code_Site = "LO"

$JCAlias = (Get-Mailbox -RecipientTypeDetails sharedmailbox | Where-object {($_.CustomAttribute1 -eq $Item.Code_Site)}.Alias)

ERROR : The property Alias cannot be found on this object. Verify that the property exist....

Get-Mailbox has a property called alias..

so something is wrong in my statement.....

PS I I remove .alias  I get the name of the mailbox

$JC = Get-Mailbox -RecipientTypeDetails sharedmailbox | Where-object {($_.CustomAttribute1 -eq $Item.Code_Site)}

BUT this is not what I need....
François VDCIcT service DeskAsked:
Who is Participating?
 
oBdACommented:
The closing round bracket is not at the correct position; it needs to be right before the dot.
$JCAlias = (Get-Mailbox -RecipientTypeDetails sharedmailbox | Where-object {($_.CustomAttribute1 -eq $Item.Code_Site)}).Alias

Open in new window

0
 
Jeremy WeisingerSenior Network Consultant / EngineerCommented:
Your syntax is off a bit. Try this:
$Item.Code_Site = "LO"

$JCAlias = (Get-Mailbox -RecipientTypeDetails sharedmailbox | Where-object {($_.CustomAttribute1 -eq $Item.Code_Site)} | Select -ExpandProperty Alias)

Open in new window

0
 
oBdACommented:
Suggest a split. Both are valid solutions, just two ways to achieve the same thing.
1
 
Jeremy WeisingerSenior Network Consultant / EngineerCommented:
Both valid.
I should also clarify that the original question had the wrong syntax. oBdA’s syntax is, of corse, correct.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.