Page 1 of 1

richtextbox and array data

Posted: Tue Mar 19, 2019 1:01 pm
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
$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?

Re: richtextbox and array data

Posted: Tue Mar 19, 2019 1:18 pm
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.