Creating accounts AD 2k8 PowerShell - Carriage Return in addresses

Fred Acme
Fred Acme used Ask the Experts™

How are you today ?

I've got a problem with Excel, PowerShell and AD (2008 or 2012).
In AD, we have some users with an address on 2 lines (See 2-LINES.JPG attached).

In Excel, I use ALT+ENTER (or "Wrap up automatically" button) to make the return (See 2-LINES-EXCEL.JPG).

Then, I save the file in csv with  coma format.

When I lauch my script (this is a part of the script) : New-ADUser -StreetAddress $_.streetaddress
The address is on a signle line.

What should I do to make the address on two lines ?

Thank you for your help !

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Patrick BogersDatacenter platform engineer Lindows


In the csv you can add `r`n between the two lines like below.
"This is the first line`r`nThe Second"

Shaun VermaakSenior Consultant
Awarded 2017
Distinguished Expert 2018

You can also open CSV in Excel and use this formula

Open in new window

Top Expert 2014
Testing either of those solutions doesn't work for me.  PS just treats the `r`n literally and that gets put in the streetaddress attribute.

Odd thing is, I could've sworn that I had previously done an import of a multiline attribute where lines were just separated by a newline (`n), but it's not working now so my memory is probably just wrong.

When you export a multiline attribute like streetaddress to a .CSV using PS, you see that the lines are separated by <CR><LF> (`r`n).  The only way I've been able to get this to work is to do a replace operation on the imported .CSV data (which has the newline separator as in the original question).  Partial code for just the replace operation:
-StreetAddress "$($_.streetaddress -replace "\n","`r`n")"

Open in new window

Fred AcmeIT Technician


Hello !

Thank you everybody for your help.

I'll test it rapidly.
Fred AcmeIT Technician



Your command is great !

I used it yesterday and all my accounts are OK :)

Thank you !

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial