Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 61
  • Last Modified:

List title next to name in listbox

Can you help me how a users job title next to their name in a list box?  The code below lists all users in one OU.  I would like to list their job title from the job title field next to their name but cant figure out how.

$listbox3.Items.Clear();
	$here3 = Get-ADUser -SearchBase "OU=Staff,OU=Amigos,dc=homelab,dc=com" -Filter * | Get-ADUser -Property DisplayName, title | Select -expandproperty Name
	$here3 = $here3 | sort-object
	load-listbox -Listbox $listbox3 -Items $here3

Open in new window

0
Roccat
Asked:
Roccat
  • 3
  • 2
2 Solutions
 
get-ADuser -F ($_.Name -eq "Todd")Systems AdministratorCommented:
Does this help?  

https://community.spiceworks.com/topic/250656-how-to-create-a-multi-column-listbox-in-powershell-win-forms

maybe add something like this?
$listbox3.Columns.Add('Name')
$listbox3.Columns.Add('Title')
0
 
oBdACommented:
Why don't you just use Out-GridView?
And there's no need to stress AD by calling Get-ADUser twice.
$here3 = Get-ADUser -SearchBase "OU=Staff,OU=Amigos,dc=homelab,dc=com" -Filter * -Property DisplayName, title | Sort-Object
$here3 | Out-GridView

Open in new window

When used with -PassThru, it can even be used to let a user select one (-OutputMode Single) or multiple (-OutputMode Multiple) items from the list.
0
 
RoccatAuthor Commented:
I created a GUI using poweshell studio with a listbox element that gets populated with the code above.  I am not sure how to utilize the gridview and also could not figure out how to use the columns mentioned above. Perhaps this is not something I can figure out with at this time.
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
RoccatAuthor Commented:
Thank you for the tip about not stressing the ad with multiple get-user requests.
0
 
oBdACommented:
The code snippet is a full functional example. Where exactly do you have problems?
Out-Gridview will automatically create a column for each property of the objects passed. If you only want a subset of the objects' properties, you pass them through the usual suspect, that is, Select-Object:
$here3 = Get-ADUser -SearchBase "OU=Staff,OU=Amigos,dc=homelab,dc=com" -Filter * -Property DisplayName, title | Sort-Object
$here3 | Select-Object -Property DisplayName, Title, samAccountName | Out-GridView

Open in new window

0
 
RoccatAuthor Commented:
The code snippet does work. Thank you for the example. I just don't know how I could use the out-grid view in my gui. I have attached a picture of what I am working on and I put an arrow pointing to my list box.listbox
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now