Exporting to CSV Questions

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.


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"

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.

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

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"

Doh, I’m slow apparently! :smiley:


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. :slight_smile:

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

Tableau Online Training
is good?