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.
Post Reply
Rabid138
Posts: 10
Joined: Thu Oct 03, 2019 6:22 am

Multi-line textbox output

Post by Rabid138 » Wed Oct 09, 2019 10:13 am

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.

Code: Select all

$form1_Load={
#TODO: Initialize Form Controls here
$SPN = Get-ADComputer MYCOMPUTER -Properties servicePrincipalName | select -ExpandProperty servicePrincipalName
$textbox1.Text = "$SPN"
}
How do I get each result on a new line? Right now it outputs it as one line with a space between each entry.

User avatar
jvierra
Posts: 13793
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Multi-line textbox output

Post by jvierra » Wed Oct 09, 2019 10:21 am

Simple. Just do it:

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

User avatar
jvierra
Posts: 13793
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Multi-line textbox output

Post by jvierra » Wed Oct 09, 2019 10:24 am

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 » Wed Oct 09, 2019 10:28 am

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 » Wed Oct 09, 2019 10:50 am

This gives the desired result. Thanks!

Code: Select all

$SPN = Get-ADComputer MYCOMPUTER -Properties servicePrincipalName | select -ExpandProperty servicePrincipalName

foreach ($item in $SPN)
{
$item = $item -split ' '
$textbox1.AppendText("$($item)`n")
}

User avatar
jvierra
Posts: 13793
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Multi-line textbox output

Post by jvierra » Wed Oct 09, 2019 10:53 am

Now do this:

Code: Select all

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

User avatar
jvierra
Posts: 13793
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Multi-line textbox output

Post by jvierra » Wed Oct 09, 2019 11:03 am

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 3 times

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

Re: Multi-line textbox output

Post by Rabid138 » Wed Oct 09, 2019 3:28 pm

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

Post Reply