Try this in your Array section:

$tslist += $ts.Name + "`n" (see below)


Array
$adverts = Get-WMIObject -ComputerName $global:siteservercas -Namespace 
"root\sms\site_$global:sitecodecas" -class sms_advertisement -filter 
"collectionid = 'SMS000US'" -Credential $global:sccmcred
     foreach ($advert in $adverts) {
          $tsid = $advert.PackageID
          $ts = Get-WMIObject -ComputerName $global:siteservercas -Namespace 
"root\sms\site_$global:sitecodecas" -class sms_tasksequencepackage -filter 
"PackageID = '$tsid'" -Credential $global:sccmcred
          $tslist += $ts.Name + "`n"
     }


From: listsad...@lists.myitforum.com<mailto:listsad...@lists.myitforum.com> 
[mailto:listsad...@lists.myitforum.com] On Behalf Of Daniel Ratliff
Sent: Tuesday, December 03, 2013 8:56 AM
To: powershell@lists.myitforum.com<mailto:powershell@lists.myitforum.com>; 
script...@lists.myitforum.com<mailto:script...@lists.myitforum.com>
Subject: [powershell] PoSH - WinForms - RichTextBox wont appendtext on newline?

I have been banging my head against this for the last day or two and cannot 
figure out what is different. I am trying to display a RichTextBox using a 
ForEach loop of on array. The problem is I cannot get the items to display on 
separate lines! I have tried all kinds of different ways to AppendText or 
Text+=. The Array is a System.Management.Object from ConfigMgr via WMI, so I 
make sure to convert that to string. Any ideas? I am hoping there is something 
glaring that I am missing.

Whats happening
Text1text2text3text4

[cid:image001.png@01CEF019.55D564A0]

What I want
Text1
Text2
Text3
Text4

Ways I have tried to add a new line
`n
`r`n
[SystemEnvironment]::NewLine
Char[10] + Char [13]

Array
$adverts = Get-WMIObject -ComputerName $global:siteservercas -Namespace 
"root\sms\site_$global:sitecodecas" -class sms_advertisement -filter 
"collectionid = 'SMS000US'" -Credential $global:sccmcred
     foreach ($advert in $adverts) {
          $tsid = $advert.PackageID
          $ts = Get-WMIObject -ComputerName $global:siteservercas -Namespace 
"root\sms\site_$global:sitecodecas" -class sms_tasksequencepackage -filter 
"PackageID = '$tsid'" -Credential $global:sccmcred
          $tslist += $ts.Name + "`n"
     }

Form/RichTextBox
$DeployForm = New-Object System.Windows.Forms.Form
$DeployForm.Text = "Deployments"
$DeployForm.Size = New-Object System.Drawing.Size(550,450)
$DeployForm.DataBindings.DefaultDataSourceUpdateMode = 0
$DeployForm.StartPosition = "CenterScreen"
$DeployForm.MinimizeBox = $False
$DeployForm.MaximizeBox = $False
$DeployForm.FormBorderStyle = "Fixed3D"
$DeployForm.Topmost = $True

$DeployTextBox = New-Object System.Windows.Forms.RichTextBox
$DeployTextBox.Location = New-Object System.Drawing.Size(5,5)
$DeployTextBox.Size = New-Object System.Drawing.Size(520,400)
$DeployTextBox.Multiline = $True
$DeployTextBox.ReadOnly = $True
$DeployTextBox.visible = $True
$DeployTextBox.Font = "Lucida Console"
foreach ($tsitem in $tslist) {
     $tsitem = $tsitem | out-string
     $DeployTextBox.AppendText($tsitem + [char]13 + [char]10)
     #$DeployTextBox.AppendText($tsitem + "`r`n")
     #$DeployTextBox.AppendText("$tsitem`n")
     #$DeployTextBox.Text += $tsitem + "`r`n"
}

$DeployForm.Controls.Add($DeployTextBox)

$DeployForm.Add_Shown({$DeployForm.Activate()})
[void] $DeployForm.ShowDialog()


Daniel Ratliff


The information transmitted is intended only for the person or entity to which 
it is addressed
and may contain CONFIDENTIAL material. If you receive this material/information 
in error,
please contact the sender and delete or destroy the material/information.

================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1

================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1
**********************************************************
Electronic Mail is not secure, may not be read every day, and should not be 
used for urgent or sensitive issues 


================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1

<<inline: image001.png>>

Reply via email to