Link to home
Start Free TrialLog in
Avatar of sirbounty
sirbountyFlag for United States of America

asked on

'Really' trimming in powershell

I'm trying to write this data to the Notes field for an AD object, but I'm seeing some extra 'spacing' that I don't want.

First line:first value
 Second line: second value [note the leading space]
 [this continues to the end]
[and then I have an extra blank line that I don't want, but I realize it's because of my `r`n - how can I remedy?]

Am I missing something in my code that would correct this?
 [string]$info = $infoField.Keys | foreach {if ($infofield.item($_) -ne $null) {
                "{0}:{1}`r`n" -f $_.trim(),$infoField.item($_)}}
 $attributes.add('info',$info)

Open in new window

And then $attributes is applied to the New-ADGroup with the -otherAttributes parameter...
ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sirbounty

ASKER

It did line everything up on the leftmost margin, but it also split my key/values where they contained spaces.

So now I have

First
line:
first
value
Second
line:
second
value
Ah, but splitting on `n may have done the trick...still testing...
Much obliged! :^)
:-)