return only selected values of a property

Welcome Forums General PowerShell Q&A return only selected values of a property

This topic contains 3 replies, has 2 voices, and was last updated by

 
Participant
4 years, 3 months ago.

  • Author
    Posts
  • #18547

    Participant
    Points: 0
    Rank: Member

    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

    Keymaster
    Points: 1,673
    Helping HandTeam Member
    Rank: Community Hero

    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

    Keymaster
    Points: 1,673
    Helping HandTeam Member
    Rank: Community Hero

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

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

    Participant
    Points: 0
    Rank: Member

    Excellent Don.

    The above command works perfectly as expected.

The topic ‘return only selected values of a property’ is closed to new replies.