Removing crlf characters

I have a script to pull data from Active Directory. The attribute field called streetaddress will possibly contain multiline data like:

Address1

Address2

Address3

 

I want to remove the crlf characters and end up with

Address1 Address2 Address3. I can do this in .NET very easily but not in powershell.

I tried using $tempaddress.replace(char[10],"") or $tempaddress.replace(char(10),"", etc but it throws exceptions.

In .net I used

Dim st2 As String = Replace(st, Chr(10), "")
st2 = Replace(st2, Chr(13), " ")

 

 

 

Parents
  • I realize that this thread is ancient, but this is what I finally worked out to do this that works in powershell:

    ((Get-Content -path C:\test\smallnodes.txt -Raw) -replace ([char]13+[char]10),'' )| Set-Content -encoding ASCII -path C:\test\smallnodes2.txt

Reply
  • I realize that this thread is ancient, but this is what I finally worked out to do this that works in powershell:

    ((Get-Content -path C:\test\smallnodes.txt -Raw) -replace ([char]13+[char]10),'' )| Set-Content -encoding ASCII -path C:\test\smallnodes2.txt

Children
No Data