Converting ComboBox value to new value

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.
Locked
gdavies
Posts: 15
Last visit: Fri Oct 08, 2021 11:51 am

Converting ComboBox value to new value

Post by gdavies »

I have a form used to create new user accounts in AD. We have multiple locations, each with their own OU and user accounts are created in the OU for the location they are based in.
A standing requirement is the description attribute contains an abbreviation of their location followed by - <preformatted data>

The location is selected from a combobox, the script then adds the rest of the path and creates the ID in the correct OU. However, to remove the need for manual editing of the script created users I want to take the value selected from the location list and convert it to the required information for the description field.
So, if someone is in Colorado the OU name is Colorado, the abbreviation used in the description for this is CO. I want to take the value selected for location and get the description field populated. We have 10 locations, each with a distinct name and abbreviation. If someone is in Colorado I need the description field to show CO - <preformatted data>, if they are in New York I need it to display NY - <preformatted data>, Washington should display WA - <preformatted data>
How can I have it do this in Powershell?

gdavies
Posts: 15
Last visit: Fri Oct 08, 2021 11:51 am

Re: Converting ComboBox value to new value

Post by gdavies »

I should add, the previous iteration of the form had a button for each location which ran it's own dedicated script which contained the description field value, I am trying to streamline the form so there is a single button, the previous list of 10 buttons being replaced with a combobox containing the names of the 10 locations. The current version is ugly and inefficient

jvierra
Posts: 14981
Last visit: Fri Nov 26, 2021 10:45 pm
Answers: 14
Has voted: 3 times
Been upvoted: 11 times

Re: Converting ComboBox value to new value

Post by jvierra »

You seem to be asking us to design a whole solution for you. Forums are not useful for and do not design solutions. We can answer a specific correctly asked question but designing a whole solution would not be possible.

gdavies
Posts: 15
Last visit: Fri Oct 08, 2021 11:51 am

Re: Converting ComboBox value to new value

Post by gdavies »

I know this forum is not for ready made solutions to be provided and I'm not asking anybody to design a solution, I am asking how to do a specific thing, as in take the value selected from a list of values and use this to populate another attribute with a different value. I have the rest of the script in place I just need a pointer or a little nudge in the right direction.
Can I use IF statements for this? Because there are 10 possible source values, each with a different converted value would IF work?

gdavies
Posts: 15
Last visit: Fri Oct 08, 2021 11:51 am

Re: Converting ComboBox value to new value

Post by gdavies »

I found a way around the problem, it doesn't answer what I was asking but at least I can now move on.
Again, I was not asking anybody to provide a solution I was asking for advice on what method I could use.

People tend to ask questions because they simply don't know, coming back with a scolding for not asking the question in the correct manner does nothing to help. Not everybody is an expert in Powershell so sometimes the question is not phrased exactly how an expert would phrase it because the person asking doesn't know the correct way to phrase it.

jvierra
Posts: 14981
Last visit: Fri Nov 26, 2021 10:45 pm
Answers: 14
Has voted: 3 times
Been upvoted: 11 times

Re: Converting ComboBox value to new value

Post by jvierra »

No one is scolding you; it is just how all tech forums work. Perhaps you would do better if you didn't try to ask page-long questions. Start technical questions with a short clear statement of what you are trying to accomplish and clearly state what is not happening.

In the end you seemed to be asking for someone to redesign some code that you likely inherited and found on the Internet.

I can also recommend learning basic WinForms. WinForms are challenging even for experienced professional programmers when they first try to program with them.

jvierra
Posts: 14981
Last visit: Fri Nov 26, 2021 10:45 pm
Answers: 14
Has voted: 3 times
Been upvoted: 11 times

Re: Converting ComboBox value to new value

Post by jvierra »

gdavies wrote:
Fri Oct 08, 2021 6:12 am
I know this forum is not for ready made solutions to be provided and I'm not asking anybody to design a solution, I am asking how to do a specific thing, as in take the value selected from a list of values and use this to populate another attribute with a different value. I have the rest of the script in place I just need a pointer or a little nudge in the right direction.
Can I use IF statements for this? Because there are 10 possible source values, each with a different converted value would IF work?
Some more hints. You can add anything to a ComboBox you want by almost any method. The issue is that your request is too vague. Here is a article that explains how to use a ComboBox. You should start by reading it.

https://info.sapien.com/index.php/guis/ ... ox-control

The simplest method is to just add items using the "Add" method of the CB as you select them by whatever selection method you are using.

I still strongly suggest learning WinForms first and be sure you know PowerShell at a sufficient level to understand how it is used in WinForms.

Here is a free and excellent book that will step you through both.

Windows PowerShell TFM

Locked