3

I want to search all the properties of an Active Directory user for a particular phone number/extension.

I can get all the properties like so:

get-aduser joesmith -Properties *

but I want to filter the results for, say extension 1234 (which may be in many places, like extensionAttribute1, OfficePhone, HomePhone, Mobile, etc).

I tried:

get-aduser joesmith -Properties * | where-object {$_ -like "*1234*" }

but where-object wants $_.value, and I don't know the precise value.

How should I search the values for multiple properties? I'd like to see results like:

mobile        1234
officephone   12345
othermobile   61234

1 Answer 1

4

To iterate through the values for properties you don't know the names of (i.e OfficePhone, CustomAttribute2, mobile), you can use the following:

get-aduser joesmith -Properties * | foreach-object { 
  foreach ($property in $_.PSObject.Properties) {
    if ($property.value -like "*1234*") {
      "$($property.name) $($property.value)"
    }
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Alternatively you could use Get-Member such as: get-aduser joesmith -prop *|gm -MemberType Property|select -ExpandProperty name|%{if($test.$_ -match "@philips"){[pscustomobject]@{Name=$_;Value=$test.$_}}} ...that might give you something easier to work with too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.