richtextbox and array data

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 5 years and 1 week 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
User avatar
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

richtextbox and array data

Post by mqh77777 »

I am doing a gwmi of a key. This key returns an array of data. Example: {1,16,5,7} if I run the following in PowerShell ISE it works.

Code: Select all

$Reason = (gwmi -ComputerName 'RemoteSystem' -Class mbam_volume -Namespace root\microsoft\mbam).ReasonsForNoncompliance
$Reason

It will return 
1
16
5
7
But I can't get Append.Text to display the same array information in my RichTextBox.

Code: Select all

$buttonWhyBitLockerFailed_Click = {
	$textPC = $PCNameBox.Text
	$statusbar1.text = 'Checking BitLocker, please wait...'
	$richtextbox_output.Clear()
	
	$Reason = (Get-WmiObject -ComputerName '$TextPC' -Class mbam_volume -Namespace root\microsoft\mbam).ReasonsForNoncompliance
	
	if ($Reason -ne "")
	{
     		$statusbar1.text = 'All done!'
		$richtextbox_output.AppendText("MBAM Policy requires this volume to be encrypted but it is not.  Errors are: $Reason")
				
	}

}

I've tired $richtextbox.lines = $Results and that too displays nothing. How do I display the contents of an Array?
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: richtextbox and array data

Post by davidc »

Whenever setting text in a RichTextBox or TextBox you must make sure you convert the objects to strings

Code: Select all

$textBox.Text = $results | Out-String

Note: The RichTextBox's Lines property expects an array of strings.
David
SAPIEN Technologies, Inc.
This topic is 5 years and 1 week 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