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: 236
Joined: Tue Feb 25, 2014 1:01 pm

richtextbox and array data

Post by mqh777 » Tue Mar 19, 2019 1:01 pm

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: 5838
Joined: Thu Aug 18, 2011 4:56 am

Re: richtextbox and array data

Post by davidc » Tue Mar 19, 2019 1:18 pm

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.