Page 1 of 2

Click button and search AD

Posted: Thu Oct 18, 2018 10:16 am
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?

Re: Click button and search AD

Posted: Fri Oct 19, 2018 8:01 am
by davidc
[TOPIC MOVED TO POWERSHELL GUIS FORUM BY MODERATOR]

Re: Click button and search AD

Posted: Fri Oct 19, 2018 9:38 am
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".

Re: Click button and search AD

Posted: Fri Oct 19, 2018 10:19 am
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?

Re: Click button and search AD

Posted: Fri Oct 19, 2018 10:33 am
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.

Re: Click button and search AD

Posted: Fri Oct 19, 2018 10:43 am
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.

Re: Click button and search AD

Posted: Fri Oct 19, 2018 11:25 am
by jvierra
Here are some videos that will help you get started with forms:

https://www.youtube.com/user/SAPIENTech/search?query=forms

Re: Click button and search AD

Posted: Fri Oct 19, 2018 1:47 pm
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

Re: Click button and search AD

Posted: Fri Oct 19, 2018 2:12 pm
by jvierra

$listbox1.DataSource = [collections.arraylist]Get-AdGroup -Filter "Name -like 'SCCM*'"
$listbox1.DisplayMember = 'Name'

Re: Click button and search AD

Posted: Tue Oct 23, 2018 7:13 am
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.