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.
This topic is 4 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
Rabid138
Posts: 10
Last visit: Fri Nov 03, 2023 5:04 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.     #TODO: Initialize Form Controls here
  3.     $SPN = Get-ADComputer MYCOMPUTER -Properties servicePrincipalName | select -ExpandProperty servicePrincipalName
  4.     $textbox1.Text = "$SPN"
  5. }
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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Multi-line textbox output

Post by jvierra »

Simple. Just do it:

$textbox.Lines = = Get-ADComputer MYCOMPUTER -Properties servicePrincipalName | select -ExpandProperty servicePrincipalName
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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
Last visit: Fri Nov 03, 2023 5:04 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
Last visit: Fri Nov 03, 2023 5:04 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.     foreach ($item in $SPN)
  4.     {
  5.         $item = $item -split ' '
  6.         $textbox1.AppendText("$($item)`n")
  7.     }
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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 200 times
Rabid138
Posts: 10
Last visit: Fri Nov 03, 2023 5:04 am

Re: Multi-line textbox output

Post by Rabid138 »

Thank you very much. This got me on the right track!
This topic is 4 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked