"" insted of empty field (Export-CSV)

Get-ADUser -Filter  'enabled -eq $true' -SearchBase "ou=favrskov,dc=favrskov,dc=local" -Properties * | Select Displayname, title, emailaddress, description | Export-Csv  "c:\temp\somefile.csv" -Encoding Unicode

Example CSV:

"ANDY", "SYSADMIN1", "M@M.EU", "GUEST"
"BOB", "SYSADMIN2", "F@F.EU", "ODD"
"DOH", "SYSADMIN3",, "ODD"

Who do i get "DOH" to be: "DOH", "SYSADMIN3","", "ODD"? (empty field "" insted of nothing)

Mike
LVL 1
mikeydkAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
With calculated properties, for example:
Get-ADUser -Filter 'enabled -eq $true' -SearchBase "ou=favrskov,dc=favrskov,dc=local" -Properties * |
	Select-Object -Property `
		@{Name="Displayname"; Expression={If ($_.DisplayName) {$_.DisplayName} Else {""}}}, 
		@{Name="title"; Expression={If ($_.title) {$_.title} Else {""}}}, 
		@{Name="emailaddress"; Expression={If ($_.emailaddress) {$_.emailaddress} Else {""}}}, 
		@{Name="description"; Expression={If ($_.description) {$_.description} Else {""}}} |
	Export-Csv -Path "c:\temp\somefile.csv" -NoTypeInformation -Encoding Unicode

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
A more indirect but less bloated (and more generic) way is to change the converted output:
( Get-ADUser -Filter 'enabled -eq $true' -SearchBase "ou=favrskov,dc=favrskov,dc=local" -Properties * |
    ConvertTo-CSV -NoType
) -replace ',,', ',"",' -replace ',$', ',""' -replace '^,', '"",' |
  Out-File "c:\temp\somefile.csv" -Encoding Unicode

Open in new window

The reason why you get "nothing" is because those properties are $null, and no empty string as you expect. This is intentional, to keep the property type consistent for all rows.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.