How to find any propertie that has a specific value

This topic contains 6 replies, has 4 voices, and was last updated by  Vandrey Trindade 2 years ago.

  • Author
  • #45352

    Vandrey Trindade


    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

    Don Jones

    That'd be the Where-Object command.

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

  • #45386

    Vandrey Trindade

    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

    Wilson Acosta

    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

    Vandrey Trindade

    Wilson Acosta,

    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

    random commandline
    Get-ADUser -Filter 'Name -like "*Vandr*"'
  • #45498

    Vandrey Trindade

    random commandline,

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

You must be logged in to reply to this topic.