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

Daoust ICT
Daoust ICT used Ask the Experts™
on
$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....
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
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

Jeremy WeisingerSenior Network Consultant / Engineer
Commented:
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

Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
Suggest a split. Both are valid solutions, just two ways to achieve the same thing.
Jeremy WeisingerSenior Network Consultant / Engineer

Commented:
Both valid.
I should also clarify that the original question had the wrong syntax. oBdA’s syntax is, of corse, correct.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial