How to find any propertie that has a specific value

This topic contains 6 replies, has 4 voices, and was last updated by Profile photo of Vandrey Trindade Vandrey Trindade 5 months ago.

  • Author
    Posts
  • #45352
    Profile photo of Vandrey Trindade
    Vandrey Trindade
    Participant

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

    That'd be the Where-Object command.

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

  • #45386
    Profile photo of Vandrey Trindade
    Vandrey Trindade
    Participant

    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
    Profile photo of Wilson Acosta
    Wilson Acosta
    Participant

    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
    Profile photo of Vandrey Trindade
    Vandrey Trindade
    Participant

    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
    Profile photo of random commandline
    random commandline
    Participant
    Get-ADUser -Filter 'Name -like "*Vandr*"'
    
  • #45498
    Profile photo of Vandrey Trindade
    Vandrey Trindade
    Participant

    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.