return only selected values of a property

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

  • Author
    Posts
  • #18547
    Profile photo of ahmed ali
    ahmed ali
    Participant

    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
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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
    Profile photo of Don Jones
    Don Jones
    Keymaster

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

    Get-MailboxPermission -identity alias | Select User | Where { $_.user -like 'whatever*' }
    
  • #18551
    Profile photo of ahmed ali
    ahmed ali
    Participant

    Excellent Don.

    The above command works perfectly as expected.

You must be logged in to reply to this topic.