Output in Listbox is incomplete in powershell GUI

Hi, when I try to output the edmpolicy property from a AD Group the output is incomplete in a listbox. It should look like this {+SOFTWARE/75_MS_VS_CPLUSPLUS_2K8_SP1, +SOFTWARE/APP50_VMWAREPLUGIN6_041416} but it only shows +SOFTWARE/APP50_VMWAREPLUGIN6_041416. Is it some formatting I’m missing? Is it possible to remove the +SOFTWARE/ output also? Thanks for any help in advance.

$buttonViewZService_Click= {
	#TODO: Place custom script here
	
	$vbmsg = new-object -comobject wscript.shell
	if ($list2.selecteditems.count -gt 1) { $vbmsg1 = $vbmsg.popup("You may only select one Group at a time.", 0, "Error", 0) }
	elseif ($list2.selecteditems.count -lt 1) { $vbmsg1 = $vbmsg.popup("Please select an Group to view.", 0, "Error", 0) }
	else
	{
		
		$exprString = '$list2.SelectedItems | foreach-object {$_.tag} | foreach-object {$_.name}'
		$endapp = invoke-expression $exprString
		import-module activedirectory
			
		
		$list1.visible = $true
		$columnnames = "Name", "Path"
		$list1.Columns[1].text = "Install Date"
		$list1.Columns[1].width = 129
		$list1.Columns[0].text = "Name"
		$list1.Columns[0].width = ($list1.width - $list1.columns[1].width - 25)
		
		$list1.items.Clear()
		$systeminfoerror = $null
		import-module activedirectory
		
		$software = Get-ADgroup -LDAPFilter "(&(Name=$endapp))" -Property *
				
		$columnproperties = "Name"
		foreach ($app in $software)
		{
			$item = new-object System.Windows.Forms.ListViewItem($app.edmPolicy)
			if ($app.InstallDate -ne $null)
			{
				$item.SubItems.Add($app.Result)
			}
			$item.Tag = $app
			$list1.Items.Add($item) > $null
		}
	}
}

It looks like the edmpolicy attribute is an array. You will probably have to do a foreach loop for $app.edmpolicy and put your code for adding to the list in that foreach loop.

Hi, could you please give me an example? Sorry I’ve been struggling with this all weekend. Is there also a way to remove the +SOFTWARE/ from the output also? Thanks for your help.

Sure thing. I’ll modify the section of your code that it would go into:

foreach ($app in $software) {
    # Process each item in the edmPolicy array and remove the leading text, then add to the list
    foreach ($policy in $app.edmPolicy) {
        $PolicyName = $policy -replace "\+SOFTWARE\/"
        $item = new-object System.Windows.Forms.ListViewItem($PolicyName)
        if ($app.InstallDate -ne $null) {
            $item.SubItems.Add($app.Result)
        }
        $item.Tag = $app
        $list1.Items.Add($item) > $null
    }
}

Let me know if that works for you.

That works great Matt. Thanks for your help!! :slight_smile:

Happy to help!