locked
PowerShell ADSI search for Custom attribute RRS feed

  • Question

  • Hi

    I need to return an AD custom attribute from Servers that don't (and can't) have the AD module installed

    Here what I have so far but I can't find where (if) the attribute I'm after is a property of the object I'm returning.

    $server = $env:computername

    (([adsisearcher]"(&(objectCategory=Computer)(name=$server))").findone().properties['extensionAttribute5'])

    Help Please

    Cheers

    Alex

    Wednesday, January 31, 2018 8:40 AM

Answers

  • $server = $env:computername + '$'
    if ($computer = ([adsisearcher]"(samaccountname=$server)").findone()){
    	$computer.properties['extensionattribute5']
    }
    

    Id the attribute isn't set you will get an error.

    The query you were using won't necessarily bring back the correct system as "Name" is not unique in AD although the extra names would have to be disabled and in different OUs.

    By default the "searcher" should return all properties.


    \_(ツ)_/

    • Marked as answer by Mr P Wednesday, January 31, 2018 11:49 AM
    Wednesday, January 31, 2018 8:57 AM

All replies

  • $server = $env:computername + '$'
    if ($computer = ([adsisearcher]"(samaccountname=$server)").findone()){
    	$computer.properties['extensionattribute5']
    }
    

    Id the attribute isn't set you will get an error.

    The query you were using won't necessarily bring back the correct system as "Name" is not unique in AD although the extra names would have to be disabled and in different OUs.

    By default the "searcher" should return all properties.


    \_(ツ)_/

    • Marked as answer by Mr P Wednesday, January 31, 2018 11:49 AM
    Wednesday, January 31, 2018 8:57 AM
  • Thanks JRV
    Wednesday, January 31, 2018 11:50 AM