I have a script to pull data from Active Directory. The attribute field called streetaddress will possibly contain multiline data like:
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,"") 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), " ")
This should work:
even this schould work:
$lf = [char]10
Neither example resolves the problem.
I get an error trying to use the char command as well.
The term 'char' is not recognized as a cmdlet, function.......
Please pay attention to the case.
It's not char but [char]10
Types are always written in this way in Powershell.
I was actually using the correct syntax and mistyped it here. I think more in .net terms thsn powershell which I am still learning. Regular expression replacements did not work because it only read the string until the first crlf was encountered. Replacing [char]10 with nothing and [char]13 with a space solved the problem. Thanks for the help. I tried to reply last night but the site appeared to be offline.
Here's a quick line to do the same.
Since the Address is a multilined string you can split the string at the newline char (`n in PoSh) and join it back to one string.
Powered by IDERA