How to find any propertie that has a specific value

Welcome Forums General PowerShell Q&A How to find any propertie that has a specific value

This topic contains 6 replies, has 4 voices, and was last updated by

 
Participant
2 years, 4 months ago.

  • Author
    Posts
  • #45352

    Participant
    Points: 25
    Rank: Member

    Hi,

    Newbie question maybe...
    I know that to find specific properties of an object I use this command:

    Get-DistributionGroup support | fl *Object*

    Is there a way to find any properties that have a specific value?
    Like: I want to know every properties that have the value *support* in it...

  • #45371

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

    That'd be the Where-Object command.

    Get-Something | Where { $_.Property -like '*value*' } | Format-Table

  • #45386

    Participant
    Points: 25
    Rank: Member

    Don Jones,

    First, thanks for always replying.
    Didn't worked for me...

    The "$_.Property" I should change for the property that I want to check?
    Tried that to get every properties with my name as a value:
    `
    Get-ADUser username | Where {$_.Property -like "*Vandr*"} | Format-Table
    `
    Nothing returned...
    I expected to get returned: DistinguishedName, GivenName and Name

  • #45389

    Participant
    Points: 0
    Rank: Member

    This is really ugly and I'm sure there's a more efficient way of doing it, but this will technically achieve the output you're expecting:

    $User = Get-ADUser username
    $UserProps = $User | Get-Member -MemberType Properties | select -ExpandProperty Name
    foreach ($Prop in $UserProps) {
        $Prop | ? {$User.$Prop -like 'Vandr*'}
    }
    
  • #45391

    Participant
    Points: 25
    Rank: Member

    Wilson Acosta,

    Thanks!
    I don't know if there is a prettier way of doing this too...
    Added something more to get the results that I want:

    $User = Get-ADUser username
    $UserProps = $User | Get-Member -MemberType Properties | select -ExpandProperty Name
    $Properties = foreach ($Prop in $UserProps) {
        $Prop | Where {$User.$Prop -like "Vandr*"}
    }
    $Properties -join(",")
    $User | select $Properties | Format-List
    
  • #45495

    Participant
    Points: 10
    Rank: Member
    Get-ADUser -Filter 'Name -like "*Vandr*"'
    
  • #45498

    Participant
    Points: 25
    Rank: Member

    random commandline,

    That command only returns every user on AD that has "vandr" on it's name.

The topic ‘How to find any propertie that has a specific value’ is closed to new replies.