return only selected values of a property

This topic contains 3 replies, has 2 voices, and was last updated by  ahmed ali 3 years, 8 months ago.

  • Author
  • #18547

    ahmed ali

    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.

  • #18548

    Don Jones

    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.

  • #18550

    Don Jones

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

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

    ahmed ali

    Excellent Don.

    The above command works perfectly as expected.

You must be logged in to reply to this topic.