Solved

List title next to name in listbox

Posted on 2016-10-28
6
43 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 84

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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

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

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

820 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