$stringBuilder = New-Object System.Text.StringBuilder
for ($i = 0; $i -lt 10; $i++){
$stringBuilder.Append("Line $i`r`n") | Out-Null
}
$stringBuilder.ToString()
This performs much better the stanard array builder of +=
PS C:\> $stringBuilder = New-Object System.Text.StringBuilder >> for ($i = 0; $i -lt 10; $i++){ >> $stringBuilder.Append("Line $i`r`n") | Out-Null >> } >> $stringBuilder.ToString() Line 0 Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9