Solved

List title next to name in listbox

Posted on 2016-10-28
6
40 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
ID: 41864743
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 83

Expert Comment

by:oBdA
ID: 41865168
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
ID: 41865516
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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

Author Comment

by:Roccat
ID: 41865518
Thank you for the tip about not stressing the ad with multiple get-user requests.
0
 
LVL 83

Accepted Solution

by:
oBdA earned 250 total points
ID: 41865829
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
ID: 41866775
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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
A brief introduction to what I consider to be the best editor for PowerShell.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

770 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