ComboBox use

Ask your PowerShell-related questions, including questions on cmdlet development!
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 3 years and 7 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
gdavies
Posts: 15
Last visit: Fri Oct 08, 2021 11:51 am

ComboBox use

Post by gdavies »

I am not asking for anyone to write a script for me, I just need some help with something I am struggling with.
I have created a GUI, no problem, but now I realize I have created a bit of a monster.
The GUI is for use by the person who creates new AD accounts who often forgets to add group membership so I have included comboboxes with the intent of reminding her to add users to groups by making her select groups from a drop down list.
Trouble is, I can't work out how to get the dropdown lists populated.
Can anyone tell me how I get it to list the groups in an OU so she can select them?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: ComboBox use

Post by jvierra »

Please review the articles in the InfoCenter. They will explain how to use GUI controls, You can search for articles on how to use the AD CmdLets to retrieve a list of OUs for your ComboBox,
gdavies
Posts: 15
Last visit: Fri Oct 08, 2021 11:51 am

Re: ComboBox use

Post by gdavies »

There are some general instructions behind the links provided, but they do not cover what I am trying to do, I can't manually enter a list of items to populate the drop down list because the list is dynamic, and quite large.
The instructions/guides also do not help when trying to use this as part of a GUI, they provide standalone code blocks, where in the script do I insert this code?

As I said, I need to populate the drop down with the security groups found in a specific OU, I know how to get a list of groups but I don't understand how to use it in this context.

I tried adapting the code example provided in one of the guides, but I get errors because it tells me there is a missing }, I can't see where there is one missing.

The adapted code I tried is attached
code.ps1
(1018 Bytes) Downloaded 174 times
I just need a pointer to how to integrate this into my GUI so the combobox is populated with the security groups in the OU defined in the $groups variable
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: ComboBox use

Post by jvierra »

Please post your PSF file. The code you posted is not sensible without understanding your process.

When you build the Load-ComboBox function is generated for you by PSS. You appear to be trying to redefine it.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: ComboBox use

Post by jvierra »

This is all you need to do to load a ComboBox:

Code: Select all

$groups = Get-AdGroup -SearchBase 'ou=OU,dc=domain,dc=domain,dc=com'
$combobox1.DataSource = [System.Collections.ArrayList]$groups
$Combobox1.DisplayMember = 'Name'
gdavies
Posts: 15
Last visit: Fri Oct 08, 2021 11:51 am

Re: ComboBox use

Post by gdavies »

Thank you, that makes more sense, I was using the code provided herehttps://info.sapien.com/index.php/guis/ ... ox-control, I couldn't see what some of it was supposed to do.
So, sorry to be a pain, I'm trying to understand how this fits in, I used Primal Forms to create the GUI so the ComboBox variable has already been created and the display configuration is set by PF. How do I relate the code you provided to this? The name of my ComboBox is not mentioned in the code below so I'm confused how it will relate, if I edit to use the name I already used it will cause a problem.

To expand on the GUI a little, I have multiple ComboBoxes displayed, I will have to remove some as I have a section for security groups and one for distribution groups and unless I change my AD structure I can't differentiate without adding more code and I already feel a little out of my comfort zone

The entire script is attached, it is 1453 lines but just providing a section would not give you the context I think you are looking for
code.ps1
(56.6 KiB) Downloaded 176 times
gdavies
Posts: 15
Last visit: Fri Oct 08, 2021 11:51 am

Re: ComboBox use

Post by gdavies »

How does the combobox code fit into a primalforms script?
When I export the code to Powershell the combobox is listed under #region generated form objects and has a code block to tell Powershell how and where to display it but it is not listed anywhere else. It is not listed in #Generated Event Script Blocks. So I don't understand where the code you provided is supposed to go to make it list the information I want in the dropdown.

Where does this code go?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: ComboBox use

Post by jvierra »

It can go in any event that you want to use to load the box.

Please review the articles in teh info center as they will teach you how to use PowerShell Studio and how to use Forms and controls. You cannot guess your way through this.

You can also click on the "Product Manual" button to get instructions on how to use PowerShell Studio.
gdavies
Posts: 15
Last visit: Fri Oct 08, 2021 11:51 am

Re: ComboBox use

Post by gdavies »

I am not using Powershell Studio, I am still using PrimalForms, Powershell Studio either does not do what I need or is so complex it would take far too long to get it done.
So, thanks for the help but it hasn't actually helped. I'm not a total novice when it comes to Powershell but I am unable to work out how to get the combobox to function as I want in a GUI designed using Primalforms. The info center articles do NOT cover what I want to do as I previously stated.
I will look for an alternative to this and just give up on the Sapien toolset
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: ComboBox use

Post by jvierra »

The information is the same for PrimalForms. Forms and controls are the same as they always have been in Windows.
This topic is 3 years and 7 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