24

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.
  • 379
  • 1
  • 3
  • 11

2 Answers2

39

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"
mjolinor
  • 66,130
  • 7
  • 114
  • 135
  • 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! – Shaun Z. Oct 15 '14 at 19:10
  • 1
    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? – mjolinor Oct 15 '14 at 19:16
  • 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? – Shaun Z. Oct 15 '14 at 19:23
  • Okay, I posted an updated answer to include a script method for that. – mjolinor Oct 15 '14 at 19:31
  • Haha 'if you really want..' (I don't, they do) Works great though!! Thank you so much for the help :) – Shaun Z. Oct 15 '14 at 19:34
  • 1
    I can't upvote till I have 15 rep.. sorry. I will come back when I have it and upvote anyway. Thanks again. – Shaun Z. Oct 15 '14 at 19:35
  • If this answer helped you, marking it as the answer using the green check mark is a good start @user3861838 – Matt Oct 15 '14 at 19:36
3

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'
Baodad
  • 2,405
  • 2
  • 38
  • 39