locked
Unable to read csv file RRS feed

Answers

  • Hi,

    Since you want to export the result to a CSV file, why not just use select.

    And in additon, based on my understanding, format commands are used to format outputs when your want to list all of them on the screen.

    So please try the below code:

    Get-ADUser -Filter * -Properties "LastLogonDate" |

    sort-object -property lastlogondate -descending |

    select name, lastlogondate -AutoSize |

    Export-csv aduser.csv


    Regards,

    Yan Li


    Yan Li

    TechNet Community Support

    • Proposed as answer by Yan Li_ Tuesday, May 22, 2012 12:43 AM
    • Marked as answer by Yan Li_ Thursday, May 24, 2012 1:35 AM
    Thursday, May 17, 2012 2:39 AM

All replies

  •  
    read that :)
     
     

    Justin Rich
    http://jrich523.wordpress.com
    PowerShell V3 Guide (Technet)
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Wednesday, May 16, 2012 6:27 PM
  • This is the second time something like this has come up and - all of a sudden I'm seconding guessing myself. But I've never really seen a really good reason for adding the weirdness of using a format* cmdlet in the middle of a pipe.

    Is there any reason you need that Format-Table in there? 


    G. Samuel Hays

    Wednesday, May 16, 2012 7:06 PM
  • I see it often, and I think people mistake it for select-object
     
    once you learn what its doing you say "why was I doing that?!"
     
    I learned the hard way myself, looking back on it, I have no idea why I'd
    even do it :)
     
    it’s a pretty common beginners mistake
     
     

    Justin Rich
    http://jrich523.wordpress.com
    PowerShell V3 Guide (Technet)
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Wednesday, May 16, 2012 7:17 PM
  • Hi,

    I have a problem that am unable to read output from powershell in csv format.

    I have used the following link to export user information from active directory using active directory powershell module

    http://blogs.technet.com/b/heyscriptingguy/archive/2010/07/20/hey-scripting-guy-how-can-i-use-windows-powershell-to-identify-inactive-user-accounts-in-active-directory-domain-services.aspx
     
     
    The actual command that I ran on active directory module is:

    Get-ADUser -Filter * -Properties "LastLogonDate" | sort-object -property lastlogondate -descending | Format-Table -property name, lastlogondate -AutoSize | Export-csv aduser.csv

    As others have indicated, the format-table is not useful in this context. I'd suggest you try replacing it with this command:

        select name, lastlogondate


    Al Dunbar

    Wednesday, May 16, 2012 9:06 PM
  • Hi,

    Since you want to export the result to a CSV file, why not just use select.

    And in additon, based on my understanding, format commands are used to format outputs when your want to list all of them on the screen.

    So please try the below code:

    Get-ADUser -Filter * -Properties "LastLogonDate" |

    sort-object -property lastlogondate -descending |

    select name, lastlogondate -AutoSize |

    Export-csv aduser.csv


    Regards,

    Yan Li


    Yan Li

    TechNet Community Support

    • Proposed as answer by Yan Li_ Tuesday, May 22, 2012 12:43 AM
    • Marked as answer by Yan Li_ Thursday, May 24, 2012 1:35 AM
    Thursday, May 17, 2012 2:39 AM