return only selected values of a property

Hi Team,

I want to return only few selected values from a parameter from powershell. Can you please advise me, tried with the below cmdlet but no luck.

$permission = (Get-MailboxPermission -Identity alias).user | Where-Object { $_.user -contains “domainname\sys*” }

I have many users with domainname/sys*, the above cmdlet does not either throw an error nor return a value.
Please advise.

You probably mean to use the -like operator. The -contains operate is not a wildcard string comparator. Common mistake; see “The Big Book of PowerShell Gotchas” for more information.

And, as a note, it might be more efficient to:

Get-MailboxPermission -identity alias | Select User | Where { $_.user -like 'whatever*' }

Excellent Don.

The above command works perfectly as expected.