Page 1 of 1

Multi-line textbox output

Posted: Wed Oct 09, 2019 10:13 am
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.

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.

Re: Multi-line textbox output

Posted: Wed Oct 09, 2019 10:21 am
by jvierra
Simple. Just do it:

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

Re: Multi-line textbox output

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

Re: Multi-line textbox output

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

Re: Multi-line textbox output

Posted: Wed Oct 09, 2019 10:50 am
by Rabid138
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")
}

Re: Multi-line textbox output

Posted: Wed Oct 09, 2019 10:53 am
by jvierra
Now do this:

Code: Select all

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

Re: Multi-line textbox output

Posted: Wed Oct 09, 2019 11:03 am
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.

Re: Multi-line textbox output

Posted: Wed Oct 09, 2019 3:28 pm
by Rabid138
Thank you very much. This got me on the right track!