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.
User avatar
Posts: 237
Last visit: Thu Jun 13, 2019 7:31 am

richtextbox and array data

Post by mqh777 »

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

It will return 
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...'
	$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
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 1 time

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.
SAPIEN Technologies, Inc.