Powershell export-csv with no headers?

76,678

Solution 1

It sounds like you basically want just text a file list of the names:

Get-Mailbox -RecipientTypeDetails RoomMailbox,EquipmentMailbox |
 Select-Object -ExpandProperty Name | 
 Set-Content -Path "$(get-date -f MM-dd-yyyy)_Resources.txt"

Edit: if you really want an export-csv without a header row:

(Get-Mailbox -RecipientTypeDetails RoomMailbox,EquipmentMailbox |
Select-Object Name |
ConvertTo-Csv -NoTypeInformation) |
Select-Object -Skip 1 |
Set-Content -Path "$(get-date -f MM-dd-yyyy)_Resources.csv"

Solution 2

Powershell 7 is out now. Still no way to export-csv without headers. I get it. Technically it wouldn't be a CSV without a header row.

But I need to remove the header row, so

$obj | convertto-csv | select-object -skip 1 |out-file 'output.csv'

P.S. I didn't need the quotes and I wanted to filter out rows based on a certain property value:

$obj | where-object {$_.<whatever property> -eq 'X' } | convertto-csv -usequotes never | select-object -skip 1 |out-file 'output.csv'
Share:
76,678

Related videos on Youtube

Shaun Z.
Author by

Shaun Z.

Updated on July 23, 2022

Comments

  • Shaun Z.
    Shaun Z. almost 2 years

    So I'm trying to export a list of resources without the headers. Basically I need to omit line 1, "Name".

    Here is my current code:

    Get-Mailbox -RecipientTypeDetails RoomMailbox,EquipmentMailbox | Select-Object Name | Export-Csv -Path "$(get-date -f MM-dd-yyyy)_Resources.csv" -NoTypeInformation
    

    I've looked at several examples and things to try, but haven't quite gotten anything to work that still only lists the resource names.

    Any suggestions? Thanks in advance!

  • Shaun Z.
    Shaun Z. over 9 years
    Well it does need to be a .csv for sure, as we are importing information into databases. We will doing this with many different things, but this resource one is the easiest/least amount of code. Will this work with a csv as well? I can test in a while. Thanks!
  • mjolinor
    mjolinor over 9 years
    If you get rid of that first line, then it doesn't have a header row any more, so technically it's not really a CSV file. Do the names need to be quoted?
  • Shaun Z.
    Shaun Z. over 9 years
    I see what you mean... What has been asked of me, is to get rid of that first line (header) so that they can code Access to pull everything from whatever columns they need. In this case, just column A. Does that make sense?
  • mjolinor
    mjolinor over 9 years
    Okay, I posted an updated answer to include a script method for that.
  • Shaun Z.
    Shaun Z. over 9 years
    Haha 'if you really want..' (I don't, they do) Works great though!! Thank you so much for the help :)
  • Shaun Z.
    Shaun Z. over 9 years
    I can't upvote till I have 15 rep.. sorry. I will come back when I have it and upvote anyway. Thanks again.
  • Matt
    Matt over 9 years
    If this answer helped you, marking it as the answer using the green check mark is a good start @user3861838