Exporting to CSV Questions

This topic contains 7 replies, has 5 voices, and was last updated by Profile photo of sss lokesh sss lokesh 1 year, 9 months ago.

  • Author
    Posts
  • #30335
    Profile photo of Luke Uhren
    Luke Uhren
    Participant

    Currently I am trying to export a list of VDI's last logon date to a .csv but I can't get it to work properly. This is what I currently am trying and I am a bit of a noob when it comes to scripting powershell in general.

    Get-ADComputer -Filter 'Name -like "*VDI*"' -Properties * | FT Name, LastLogonDate -Autosize | select-object Name, LastLogonDate | export-csv -LiteralPath "C:\test.csv"

    It won't give me the actual list from when I run this command in a /CSV Get-ADComputer -Filter 'Name -like "*VDI*"' -Properties * | FT Name, LastLogonDate -Autosize

    Can anyone help me as to what I need to do exactly to get it to automatically output to a .CSV nicely? Any help would be much appreciated.

    Thanks

  • #30336
    Profile photo of Chris Wolfenden
    Chris Wolfenden
    Participant

    Get rid of the call to Format-Table (FT). This converts the data to an array of GroupStartData objects. Just stick with:

    Get-ADComputer -Filter 'Name -like "*VDI*"' -Properties * | select-object Name, LastLogonDate | export-csv -LiteralPath "C:\test.csv"
    
  • #30337
    Profile photo of Rob Simmers
    Rob Simmers
    Participant

    Go to the Resource menu above and look at the free ebook "Powershell Gotchas". Your issue is this:

    | FT Name, LastLogonDate -Autosize
    

    Format-Table or Format-List stop the pipeline, so nothing goes beyond those commands. Remove the above from your command-line and you should be good to go.

  • #30338
    Profile photo of Luke Uhren
    Luke Uhren
    Participant

    Thanks. I knew it was just something easy, but as I said I am learning. That did it.

  • #30339
    Profile photo of Curtis Smith
    Curtis Smith
    Participant

    That's because you are doing your FT (format-table) before you select-object. FT is an output cmdlet. Once your data hits FT in the pipeline, FT sends the data to the console screen in a table format. No data is passed down the pipe to Select-Object or Export-CSV. You should take FT out completely and you should be good to go.

    Get-ADComputer -Filter 'Name -like "*VDI*"' -Properties * | select-object Name, LastLogonDate | export-csv -LiteralPath "C:\test.csv"
    
  • #30341
    Profile photo of Curtis Smith
    Curtis Smith
    Participant

    Doh, I'm slow apparently! 😀

  • #30346
    Profile photo of Rob Simmers
    Rob Simmers
    Participant

    @Curtis,

    I've had times where I refresh the page, there are no responses and I only see my post. Later I'll look and there are like 15 posts in between my post. I feel your pain. 🙂

  • #30403
    Profile photo of sss lokesh
    sss lokesh
    Participant

    thank to this question..... i need to work on it....

    Tableau Online Training
    is good?

You must be logged in to reply to this topic.