none
Can't query some attributes

    Question

  • I need to dump all attributes from AD to include the built-in ones that come with AD, Exchange attributes, and custom attributes that we added ourselves. I've using get-aduser and it doesn't seem to be able to pull all the attributes.  I have the attribute names correct, I know there are values in tyhe attributes but I get back nothing. 

    How can I run a query to pull all attributes?

    What difference is there between attributes that would cause this?

    Monday, February 13, 2012 1:58 PM

Answers

  • Nice work-around Kazun.  Unfortunately I have a csvde script that has worked for years until one day it rearranged all the collumns.  Apparently csvde doesn't guarentee a fixed column order, which we need, so I wanted to write the script in powershell.  Now I'm dealing with this odd quirk in export-csv where some attributes show up as  Microsoft.ActiveDirectory.Management.ADPropertyValueCollection.  Possibly, something wrong with our attribute?

    Csvde is a power and easy for this task.ADPropertyValueCollection - collection of attributes,you must convert to string(csvde by default),create new object with new property.

    For example:

    memberof

    #Problem
    PS C:\Users\Administrator> Get-ADUser -fi * -prop memberof| select name,membeof | ConvertTo-Csv -no
    "name","membeof"
    "Administrator","Microsoft.ActiveDirectory.Management.ADPropertyValueCollection"
    
    #Create new object
    PS C:\Users\Administrator> Get-ADUser -fi * -prop memberof| select name,@{n="memberof";e={[string]$_.memberof}}|
    >>     ConvertTo-Csv -NoTypeInformation
    >>
    "name","memberof"
    "Administrator","CN=Group Policy Creator Owners,CN=Users,DC=contoso,DC=com CN=Domain Admins,CN=Users,DC=contoso,DC=com
    CN=Enterprise Admins,CN=Users,DC=contoso,DC=com CN=Schema Admins,CN=Users,DC=contoso,DC=com CN=Administrators,CN=Builti
    n,DC=contoso,DC=com"
    
    
    #Using csvde
    csvde -r "(objectClass=user)" -l "name,memberof" -f C:\posh.csv
    
    PS C:\Users\Administrator> gc C:\posh.csv
    DN,memberOf,name
    "CN=Administrator,CN=Users,DC=contoso,DC=com","CN=Group Policy Creator Owners,CN=Users,DC=contoso,DC=com;CN=Domain Admi
    ns,CN=Users,DC=contoso,DC=com;CN=Enterprise Admins,CN=Users,DC=contoso,DC=com;CN=Schema Admins,CN=Users,DC=contoso,DC=c


    • Edited by KazunMVP Monday, February 13, 2012 3:14 PM
    • Marked as answer by olsonta Monday, February 13, 2012 3:14 PM
    Monday, February 13, 2012 3:13 PM

All replies

  • One attrubute returns this value:

    Microsoft.ActiveDirectory.Management.ADPropertyValueCollection
    Monday, February 13, 2012 2:05 PM
  • Only a subset of properties are returned by default.  To return all properties, use this command:

    Get-ADUser -Properties * -Filter *

    To get specific additional properties, specify them by name, separated by commas, for the -Properties parameter.

    Grant Ward, a.k.a. Bigteddy

    What's new in Powershell 3.0 (Technet Wiki)

    Monday, February 13, 2012 2:22 PM
  • Here's what I've been using to query our added attribute named orgSection:

    get-aduser -LDAPFilter "(objectClass=user)" -properties orgSection

    It returns this:

    Microsoft.ActiveDirectory.Management.ADPropertyValueCollection

    Monday, February 13, 2012 2:25 PM
  • get-aduser -LDAPFilter "(objectClass=user)" -properties orgSection | select *,@{n="orgSection";e={$_.orgSection}} -excl orgSection
    Monday, February 13, 2012 2:33 PM
  • Never mind!  I wrote the query incorrectly when I was specifying each attribute.  When I tried just * it showed up. 

    So, get-aduser should be able to pull any atribute that is available no matter what type it is (string, value, multi-value etc)?

    Monday, February 13, 2012 2:34 PM
  • Yes, even arrays.

    Grant Ward, a.k.a. Bigteddy

    What's new in Powershell 3.0 (Technet Wiki)

    Monday, February 13, 2012 2:44 PM
  • Not sure what I wrote incorrectly though. A straight query returns correct results.  Here's where I loose it:

    I piped the output to out-csv:.. | export-csv "e:\test.csv" -force -notypeinformation

    and my attribute turns into Microsoft.ActiveDirectory.Management.ADPropertyValueCollection

    Monday, February 13, 2012 2:49 PM
  • $prop = Get-ADUser -Identity Administrator -Properties *| gm -type properties | %{$_.Name}
    
    csvde -r "(objectClass=user)" -l ($prop -join ",") -f C:\posh.csv


    • Proposed as answer by Bigteddy Monday, February 13, 2012 3:04 PM
    Monday, February 13, 2012 2:54 PM
  • Nice work-around Kazun.  Unfortunately I have a csvde script that has worked for years until one day it rearranged all the collumns.  Apparently csvde doesn't guarentee a fixed column order, which we need, so I wanted to write the script in powershell.  Now I'm dealing with this odd quirk in export-csv where some attributes show up as  Microsoft.ActiveDirectory.Management.ADPropertyValueCollection.  Possibly, something wrong with our attribute?
    Monday, February 13, 2012 3:03 PM
  • Nice work-around Kazun.  Unfortunately I have a csvde script that has worked for years until one day it rearranged all the collumns.  Apparently csvde doesn't guarentee a fixed column order, which we need, so I wanted to write the script in powershell.  Now I'm dealing with this odd quirk in export-csv where some attributes show up as  Microsoft.ActiveDirectory.Management.ADPropertyValueCollection.  Possibly, something wrong with our attribute?

    Csvde is a power and easy for this task.ADPropertyValueCollection - collection of attributes,you must convert to string(csvde by default),create new object with new property.

    For example:

    memberof

    #Problem
    PS C:\Users\Administrator> Get-ADUser -fi * -prop memberof| select name,membeof | ConvertTo-Csv -no
    "name","membeof"
    "Administrator","Microsoft.ActiveDirectory.Management.ADPropertyValueCollection"
    
    #Create new object
    PS C:\Users\Administrator> Get-ADUser -fi * -prop memberof| select name,@{n="memberof";e={[string]$_.memberof}}|
    >>     ConvertTo-Csv -NoTypeInformation
    >>
    "name","memberof"
    "Administrator","CN=Group Policy Creator Owners,CN=Users,DC=contoso,DC=com CN=Domain Admins,CN=Users,DC=contoso,DC=com
    CN=Enterprise Admins,CN=Users,DC=contoso,DC=com CN=Schema Admins,CN=Users,DC=contoso,DC=com CN=Administrators,CN=Builti
    n,DC=contoso,DC=com"
    
    
    #Using csvde
    csvde -r "(objectClass=user)" -l "name,memberof" -f C:\posh.csv
    
    PS C:\Users\Administrator> gc C:\posh.csv
    DN,memberOf,name
    "CN=Administrator,CN=Users,DC=contoso,DC=com","CN=Group Policy Creator Owners,CN=Users,DC=contoso,DC=com;CN=Domain Admi
    ns,CN=Users,DC=contoso,DC=com;CN=Enterprise Admins,CN=Users,DC=contoso,DC=com;CN=Schema Admins,CN=Users,DC=contoso,DC=c


    • Edited by KazunMVP Monday, February 13, 2012 3:14 PM
    • Marked as answer by olsonta Monday, February 13, 2012 3:14 PM
    Monday, February 13, 2012 3:13 PM
  • Great!, thanks for the quick response too.
    Monday, February 13, 2012 3:17 PM