Click button and search AD

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 5 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

Click button and search AD

Post by mqh77777 »

Product: PowerShell Studio 2018 (64 Bit)
Build: v5.5.155
OS: Windows 10 Enterprise (64 Bit)
Build: v10.0.16299.0


We have a PowerShell Studio form that has many tabs and over 50 buttons. We want to keep users out of active directory so I want to add a button that when pressed will search for AD groups but only AD groups that begin with SCCM. Then, based on the group they choose it will add their machine to that group. I know how to do all of the PowerShell scripting to add the system but how do you make your button read AD and then capture their choice into a $variable?
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Click button and search AD

Post by davidc »

[TOPIC MOVED TO POWERSHELL GUIS FORUM BY MODERATOR]
David
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Click button and search AD

Post by jvierra »

The simple answer is to use Get-AdGroup.

$groups = Get-AdGroup -Filter "Name -like 'SCCM*'"

This will fill the variable with all groups that begin with "SCCM".
User avatar
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

Re: Click button and search AD

Post by mqh77777 »

Yes, that part is easy. I can get the groups and display them in the Richtext window. But then you have to copy/paste the group name into another textbox and then click yet another button. I want to click 1 button that does everything. Or is that not possible?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Click button and search AD

Post by jvierra »

Why do you have to copy and paste? What is it you are trying to do?

I recommend reading the articles on designing forms for administration.

https://info.sapien.com/index.php/guis/gui-design-best-practice/user-interface-design-for-administrators

Alos review the lists of articles available on the left menu of the web page. You will find more info on how to build forms and make them do what you need with very little coding.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Click button and search AD

Post by jvierra »

mqh777 wrote: Fri Oct 19, 2018 10:19 am Yes, that part is easy. I can get the groups and display them in the Richtext window. But then you have to copy/paste the group name into another textbox and then click yet another button. I want to click 1 button that does everything. Or is that not possible?
It sounds to me like you want to display the groups in a ListBox and use the "SelectedIndexChanged" event to execute the code.

Read the Spotlight article on ListBoxes.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Click button and search AD

Post by jvierra »

Here are some videos that will help you get started with forms:

https://www.youtube.com/user/SAPIENTech/search?query=forms
User avatar
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

Re: Click button and search AD

Post by mqh77777 »

ok, we're making progress. I have a listbox and 1 button. the button will query AD and get a list of groups. It then displays the groups in the listbox. The only problem is they are not listed 'one per line'. They are only 1/2 wide and all jumbled. How do you format the listbox so it looks like this?

AD group num1
AD group num2
AD group num3
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Click button and search AD

Post by jvierra »


$listbox1.DataSource = [collections.arraylist]Get-AdGroup -Filter "Name -like 'SCCM*'"
$listbox1.DisplayMember = 'Name'
User avatar
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

Re: Click button and search AD

Post by mqh77777 »

The first line in your code produces the red exclamation point and does not execute. Here is my code:

Code: Select all

$buttonSCCMAppGroups_Click = {
	$SCCMAppGroups = (Get-ADGroup -Filter { name -like "SCCMApp_*" }).name | Sort-Object
	$ListSCCMGroups.Items.Add("$SCCMAppGroups")
	}
This returns the data but it is a 1/2 wide and all jumbled together. I've tried with/without sort-object and with/without -out-string and I get the same result.
This topic is 5 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked