Array and Richtextbox

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.
Locked
User avatar
ALD Automotive
Posts: 8
Joined: Wed Feb 07, 2018 10:28 pm

Array and Richtextbox

Post by ALD Automotive » Tue Sep 18, 2018 4:38 am

Hello,
Please help me with Array and Richtextbox

Code: Select all

$user1 = $tab2_compare_group1.Text
$user2 = $tab2_compare_group2.Text
			
$group1 = Get-ADUser $user1 -Properties * | Select-Object -ExpandProperty memberof | ForEach-Object { (($_.split(","))[0]).substring(3) } | Sort-Object -CaseSensitive
$group2 = Get-ADUser $user2 -Properties * | Select-Object -ExpandProperty memberof | ForEach-Object { (($_.split(","))[0]).substring(3) } | Sort-Object -CaseSensitive
			
$Object = New-Object System.Management.Automation.PSObject
$result = $Object | Select-Object  @{ name = "Have $(Get-ADUser $user2 | Select-Object -ExpandProperty name), but don't have $(Get-ADUser $user1 | Select-Object -ExpandProperty name)          "; Expression = { (Compare-Object $group1 $group2 | Where-Object { $_.SideIndicator -eq "=>" }).InputObject | out-string } }, @{ name = "Have $(Get-ADUser $user1 | Select-Object -ExpandProperty name),but don't have $(Get-ADUser $user2 | Select-Object -ExpandProperty name)"; Expression = { (Compare-Object $group1 $group2 | Where-Object { $_.SideIndicator -eq "<=" }).InputObject | out-string } } |ft -wrap
$textboxDisplay.Text= $result
As result i receive: "Microsoft.PowerShell.Commands.Internal.Format.FormatStartData"
But i want to see 2 columns with my data at textbox(please see attachment)
And if i add "|out-string" i resecive all data in 1 row
Attachments
SAPIENS Result.jpg
SAPIENS Result.jpg (42.3 KiB) Viewed 425 times

User avatar
jvierra
Posts: 13730
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Array and Richtextbox

Post by jvierra » Tue Sep 18, 2018 6:02 am

You cannot use the output to "Format-Table" to output plain text to a textbox or a file. It is designed to output to the console.

User avatar
ALD Automotive
Posts: 8
Joined: Wed Feb 07, 2018 10:28 pm

Re: Array and Richtextbox

Post by ALD Automotive » Tue Sep 18, 2018 6:35 am

Could you give me advice?
What can i use instead?

User avatar
jvierra
Posts: 13730
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Array and Richtextbox

Post by jvierra » Tue Sep 18, 2018 10:26 am

Remove Format-Table. It is not necessary.

Locked