A Simple Text Box and a Drop down to add a User to a Group

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 9 years and 8 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
awurthmann
Posts: 6
Last visit: Wed Aug 06, 2014 10:07 pm

A Simple Text Box and a Drop down to add a User to a Group

Post by awurthmann »

A Simple Text Box and a Drop down to add a User to a Group...

Sounds simple enough. The most simplistic form a code without gui could look something like...
PowerShell Code
Double-click the code block to select all.
[string]$User = read-host " Enter username"
[string]$Group = read-host " Enter group name"
Add-ADGroupMember -Identity $Group -Member $User
In this particular case there is actually only a subset of groups that I want to allow/show. This command gets me that and puts it into an array.
PowerShell Code
Double-click the code block to select all.
$MyGroups=(Get-ADGroup -filter {Name -like "*MY*"}).Name
Now for the fun and problem. Text box input in GUI, easy! Got it. A dropdown populate by an array? Umm... Is that a combobox? A listbox? Ok lets try combobox... ok.. why cant I get $Items=$MyGroups to work right? Am I putting my code in the proper area? Man this seems harder than when I learned C#... I must be missing something, or over thinking. The next problem I am sure I will have after this is result handling. I want to tell the user what the result was in the GUI, but I'll stumble upon that when I stumble upon that.

If it is helpful I can post the full script I am trying to GUI'ify, but that seems like overkill, with all of its error handling it is 102 lines.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: A Simple Text Box and a Drop down to add a User to a Gro

Post by jvierra »

Start by reviewing the code and information in the blog. It will give you all of the answers you seek.

http://www.sapien.com/blog/topics/user- ... istrators/

Without this background you will continue to be horribly lost.

Forms building is not for non-programmers without some bit of a learning curve, hill or mountain depending on how much background you have in computer engineering.
User avatar
awurthmann
Posts: 6
Last visit: Wed Aug 06, 2014 10:07 pm

Re: A Simple Text Box and a Drop down to add a User to a Gro

Post by awurthmann »

Will do. Thanks
User avatar
awurthmann
Posts: 6
Last visit: Wed Aug 06, 2014 10:07 pm

Re: A Simple Text Box and a Drop down to add a User to a Gro

Post by awurthmann »

jvierra wrote:Start by reviewing the code and information in the blog. It will give you all of the answers you seek.
Thank you jvierra but I must be missing something again because I am still missing where I would set the combobox contents to an array or listbox if I chose to use a listbox. The blog postings where helpful though. I think I will use an Output box when and if I get to the end of the project. For the moment though I am still stuck on how to populate the combo/listbox with the items in the array.
User avatar
awurthmann
Posts: 6
Last visit: Wed Aug 06, 2014 10:07 pm

Re: A Simple Text Box and a Drop down to add a User to a Gro

Post by awurthmann »

LOL

You just have to call the function with the options you want to set. Hahaha...
PowerShell Code
Double-click the code block to select all.
Load-ComboBox $combobox1 $Items
Wow... how did I miss that. Ok.. off to my script.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: A Simple Text Box and a Drop down to add a User to a Gro

Post by jvierra »

Unfortunately I cannot read this stuff for you. I do not have a wireless connection between my eyes and your brain.

Here is a resource mentioned in the articles. You could start by reviewing the controls here: http://www.sapien.com/blog/2012/09/06/w ... owershell/
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: A Simple Text Box and a Drop down to add a User to a Gro

Post by jvierra »

Here is one of the controls referenced in the blog posts. Please read it and try all of the examples until you understand how the control works. If you have specific questions I will try to answer them. I cannot answer the question "How do I build my form?" because it is too broad.

http://www.sapien.com/blog/2011/06/21/p ... x-control/
User avatar
awurthmann
Posts: 6
Last visit: Wed Aug 06, 2014 10:07 pm

Re: A Simple Text Box and a Drop down to add a User to a Gro

Post by awurthmann »

jvierra wrote:Unfortunately I cannot read this stuff for you. I do not have a wireless connection between my eyes and your brain.

Here is a resource mentioned in the articles. You could start by reviewing the controls here: http://www.sapien.com/blog/2012/09/06/w ... owershell/
Wow... umm sorry if I offended you somehow. I'm all set. I thought that was evident from my humbling post above. I was looking for #main section and was putting my code in the wrong section. Simple as that. Again a stupid move on my part. Fixed. No need for the sharpness. Again, I apologize if I offended you. Yes I did read the articles you posted. Yes I should have RTFMed first. I get it. I apologize. Since I am learning this IDE I am going to post other questions, if you prefer you can ignore those.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: A Simple Text Box and a Drop down to add a User to a Gro

Post by jvierra »

Not offended I just couldn't understand why you didn't understand the post. It is about as clear as it could be. I suspected you skimmed it and didn't see the information. I thought I would remind you that I cannot do the reading for you.

With learning complex and difficult technologies like PowerShell and Windows Forms you will have to do a lot of critical reading. You have a very large and steep learning curve ahead. Be sure you have a good set of reading lasses.

The blog posts are, in my opinion, a minimum requirement for using PowerShell Studio with Forms. If you can digest those lessons you will find that most things will become more obvious and you will begin to understand how to search for the bits you will need.

Good luck.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: A Simple Text Box and a Drop down to add a User to a Gro

Post by jvierra »

I would also note that your question was very vague. You posted no actual code so it was never possible to see what you were doing wrong. The best we can do is point you at the documentation and the blog posts. As you can see even that guess didn't address your actual problem.

There are many books on the technology. You would do well to obtain one and get a jump start.
This topic is 9 years and 8 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