Script Library

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 2 years and 3 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
pscyberz
Posts: 2
Last visit: Thu Dec 15, 2022 6:23 am

Script Library

Post by pscyberz »

I have a library of scripts that I plan to be calling from a GUI.

My PS form will get all scripts in a folder and add to a listbox. the user will select a script and hit execute. The script will run and output in a textbox.

This all works fine but the textbox or richtextbox dont maintain line breaks. For example:
Simple ping script:

Code: Select all

$output = .\Scripts\Example.ps1 -server 8.8.8.8
$textbox1.AppendText($output)
Simple Ping script Example.ps1

Code: Select all

ping -n 3 $server
outputs:

Code: Select all

Pinging 8.8.8.8 with 32 bytes of data: Reply from 8.8.8.8: bytes=32 time=147ms TTL=60 Reply from 8.8.8.8: bytes=32 time=148ms TTL=60 Reply from 8.8.8.8: bytes=32 time=147ms TTL=60  Ping statistics for 8.8.8.8:     Packets: Sent = 3, Received = 3, Lost = 0 (0% loss), Approximate round trip times in milli-seconds:     Minimum = 147ms, Maximum = 148ms, Average = 147ms
Is there a way to maintain line breaks?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Script Library

Post by jvierra »

Add lines to the "Lines" collection property of the textbox and they will display on separate lines.

$testbox1.Lines += $output
pscyberz
Posts: 2
Last visit: Thu Dec 15, 2022 6:23 am

Re: Script Library

Post by pscyberz »

Thanks, got it to work.

To simplify

Code: Select all

	
$simplePing = ping -n 3 '8.8.8.8'
$textbox1.Lines = $simplePing
This topic is 2 years and 3 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