Output in Listbox is incomplete in powershell GUI

This topic contains 5 replies, has 2 voices, and was last updated by Profile photo of Matt Howard Matt Howard 1 week, 3 days ago.

  • Author
    Posts
  • #58787
    Profile photo of Tony Rodal
    Tony Rodal
    Participant

    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
    		}
    	}
    }
    
  • #58793
    Profile photo of Matt Howard
    Matt Howard
    Participant

    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.

  • #58801
    Profile photo of Tony Rodal
    Tony Rodal
    Participant

    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.

  • #58808
    Profile photo of Matt Howard
    Matt Howard
    Participant

    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.

  • #58823
    Profile photo of Tony Rodal
    Tony Rodal
    Participant

    That works great Matt. Thanks for your help!! 🙂

  • #58837
    Profile photo of Matt Howard
    Matt Howard
    Participant

    Happy to help!

You must be logged in to reply to this topic.