Multi-line textbox output

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
Rabid138
Posts: 10
Joined: Thu Oct 03, 2019 6:22 am

Multi-line textbox output

Post by Rabid138 »

Brand new to Powershell Studio and so far loving it. I want to do something seemingly so simple but can't quite figure out how. For testing, I have a single form with one multi-line textbox.
  1. $form1_Load={
  2.  
  3.     #TODO: Initialize Form Controls here
  4.  
  5.     $SPN = Get-ADComputer MYCOMPUTER -Properties servicePrincipalName | select -ExpandProperty servicePrincipalName
  6.  
  7.     $textbox1.Text = "$SPN"
  8.  
  9. }
How do I get each result on a new line? Right now it outputs it as one line with a space between each entry.

jvierra
Posts: 14456
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Multi-line textbox output

Post by jvierra »

Simple. Just do it:

$textbox.Lines = = Get-ADComputer MYCOMPUTER -Properties servicePrincipalName | select -ExpandProperty servicePrincipalName

jvierra
Posts: 14456
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Multi-line textbox output

Post by jvierra »

Here are the docs. They are linked on the right context menu of each control in the toolbox.

https://info.sapien.com/index.php/guis/ ... ox-control
https://docs.microsoft.com/en-us/dotnet ... mework-4.8

Rabid138
Posts: 10
Joined: Thu Oct 03, 2019 6:22 am

Re: Multi-line textbox output

Post by Rabid138 »

While that does output servicePrincipalName to the textbox, it outputs as one long line. What I would like is to have it output each servicePrincipalName entry in AD to a newline in the textbox.

Current output in the textbox:
CmRcService/MYCOMPUTER CmRcService/MYCOMPUTER.mydomain.com

Desired output:
CmRcService/MYCOMPUTER
CmRcService/MYCOMPUTER.mydomain.com

Rabid138
Posts: 10
Joined: Thu Oct 03, 2019 6:22 am

Re: Multi-line textbox output

Post by Rabid138 »

This gives the desired result. Thanks!
  1. $SPN = Get-ADComputer MYCOMPUTER -Properties servicePrincipalName | select -ExpandProperty servicePrincipalName
  2.  
  3.    
  4.  
  5.     foreach ($item in $SPN)
  6.  
  7.     {
  8.  
  9.         $item = $item -split ' '
  10.  
  11.         $textbox1.AppendText("$($item)`n")
  12.  
  13.     }

jvierra
Posts: 14456
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Multi-line textbox output

Post by jvierra »

Now do this:

Code: Select all

$textbox.Lines = Get-ADComputer MYCOMPUTER -Properties servicePrincipalName | 
     select -ExpandProperty servicePrincipalName |
     Out-String

jvierra
Posts: 14456
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Multi-line textbox output

Post by jvierra »

Well your may might work but it is not the correct way for reasons you will understand as you learn PowerShell and Forms development. The attached file is s simple demo of how this works and how it is useful. It has two methods. OPen and run it to see what I am getting at.
Attachments
Test-Textbox_Listbox.psf
(14.86 KiB) Downloaded 30 times

Rabid138
Posts: 10
Joined: Thu Oct 03, 2019 6:22 am

Re: Multi-line textbox output

Post by Rabid138 »

Thank you very much. This got me on the right track!

Locked