none
Exporting results to csv excludes one property, why? RRS feed

  • Question

  • So I have a powershell script, part of a bigger piece that includes a GUI I designed, everything seems to work fine, apart from this query

    Get-ADUser -Filter * -Properties PasswordLastSet | 
        Where { $_.DistinguishedName -notlike '*OU=excludedOU,*' } |
            Select SamAccountName,PasswordLastSet,mail |
                    Export-Csv h:\PasswordSetDate.csv -NoTypeInformation


    I get the sAMAccountName and the date the password was set, but mail is a blank column. Running this for a single user as below

    Get-ADUser -Filter "sAMAccountName -eq '$($InputText.text)'" -properties SamAccountName,PasswordLastSet,mail | ft SamAccountName,passwordlastset,mail 

    Where $inputtext.text is the input box on the GUI for the user ID being queried, returns everything I ask for. If I change the first version to just display the results it again misses the email address out.

    Can anyone tell me why?

    I have not included the entire piece as it is onver 1200 lines and way too much to include in a question about a single query that fails to provide everything asked for

    Wednesday, October 8, 2014 2:25 PM

Answers

  • Hi,

    That property isn't returned by Get-ADUser by default, so you'll need to add it to the -Properties list:

    Get-ADUser -Filter * -Properties PasswordLastSet,mail | 
        Where { $_.DistinguishedName -notlike '*OU=excludedOU,*' } |
            Select SamAccountName,PasswordLastSet,mail |
                    Export-Csv h:\PasswordSetDate.csv -NoTypeInformation


    Don't retire TechNet! - (Don't give up yet - 13,085+ strong and growing)

    • Marked as answer by GADavies Wednesday, October 8, 2014 2:59 PM
    Wednesday, October 8, 2014 2:28 PM
  • Add mail to the list of attributes in your get-aduser command (you did this in your second example, but not the first).

    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by GADavies Wednesday, October 8, 2014 2:59 PM
    Wednesday, October 8, 2014 2:29 PM
    Moderator

All replies