'How to output Get-ADUser as csv without including the fieldnames in the first row using powershell?
I am trying to use the Get-ADUser to get a dump of the users in our system, and then output the contents to a CSV file.
However, I have not yet been able to figure out how to exclude the fieldnames from the first row in the csv file.
I want to have just the data [in csv format] but without the header row.
This code produces the data I want:
Get-ADUser -Filter * -SearchBase "OU=My,OU=OrganisationName,OU=Accounts,OU=Groups and Accounts,DC=myorg,DC=com" -Properties * |
Sort-Object -Property sn, GivenName, UserPrincipalName |
Select-Object name, sn, GivenName, UserPrincipalName |
Export-Csv -Path "C:\temp1.csv" -NoTypeInformation
But it insists on including the header row (despite the -NoTypeInformation flag).
I have tried piping the data through the command:
Format-Table -HideTableHeaders
Like so:
Get-ADUser -Filter * -SearchBase "OU=My,OU=OrganisationName,OU=Accounts,OU=Groups and Accounts,DC=myorg,DC=com" -Properties * |
Sort-Object -Property sn, GivenName, UserPrincipalName |
Select-Object name, sn, GivenName, UserPrincipalName |
Format-Table -HideTableHeaders |
Export-Csv -Path "C:\temp1.csv" -NoTypeInformation
But this converts the data in the csv file to gibberish.
Does anyone have any thoughts on how I might get rid of the header row?
thanks heaps,
David :-)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
