Creating accounts AD 2k8 PowerShell - Carriage Return in addresses


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 !

Fred AcmeIT TechnicianAsked:
Who is Participating?
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.

Patrick BogersDatacenter platform engineer LindowsCommented:

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

Shaun VermaakTechnical SpecialistCommented:
You can also open CSV in Excel and use this formula

Open in new window

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

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
Fred AcmeIT TechnicianAuthor Commented:
Hello !

Thank you everybody for your help.

I'll test it rapidly.
Fred AcmeIT TechnicianAuthor Commented:

Your command is great !

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

Thank you !
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

From novice to tech pro — start learning today.