Solved

List title next to name in listbox

Posted on 2016-10-28
6
26 Views
Last Modified: 2016-11-01
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
Comment
Question by:Roccat
  • 3
  • 2
6 Comments
 
LVL 4

Assisted Solution

by:get-ADuser -F ($_.Name -eq "Todd")
get-ADuser -F ($_.Name -eq "Todd") earned 250 total points
Comment Utility
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
 
LVL 82

Expert Comment

by:oBdA
Comment Utility
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
 

Author Comment

by:Roccat
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:Roccat
Comment Utility
Thank you for the tip about not stressing the ad with multiple get-user requests.
0
 
LVL 82

Accepted Solution

by:
oBdA earned 250 total points
Comment Utility
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
 

Author Comment

by:Roccat
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now