Exporting to CSV Questions

Welcome Forums General PowerShell Q&A Exporting to CSV Questions

This topic contains 7 replies, has 5 voices, and was last updated by

 
Participant
3 years, 5 months ago.

  • Author
    Posts
  • #30335

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 638
    Helping Hand
    Rank: Major Contributor

    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

    Participant
    Points: 0
    Rank: Member

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

  • #30339

    Participant
    Points: 1
    Rank: Member

    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

    Participant
    Points: 1
    Rank: Member

    Doh, I'm slow apparently! 😀

  • #30346

    Participant
    Points: 638
    Helping Hand
    Rank: Major Contributor

    @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

    Participant
    Points: 0
    Rank: Member

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

    Tableau Online Training
    is good?

The topic ‘Exporting to CSV Questions’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort