I have a ps script that extracts applied GPO’s from a specific OU into a CSV file and loads the name of the GPO value into a form with check list next to each GPO name and then i can select any GPO available and either select to enable or disable this GPO for a user by entering the username in the next form.
My problem is when i select multiple GPO’s to apply for a user the code runs against only one GPO(Last selected) and not for all selected, how is it possible to invoke the command on all selected GPO from the form, and is there a way after i finish entering the username the first form would re-open to go through the process again to select other GPO’s for other users?
--------------
EDIT: It has been solved thank you.
How to run code in the powershell script for selected checkboxes
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.
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.
How to run code in the powershell script for selected checkboxes
Last edited by Idler_ on Fri Feb 28, 2020 12:26 am, edited 1 time in total.
Re: How to run code in the powershell script for selected checkboxes
Your issue is that you are using only the "SelectedItem". You need to enumerate the "CheckedItems' collection to get all of the items that have been checked.
When trying to use forms it is critical that you reference the documentation to understand how to use a control. Much of the code you see on the Internet that is written with PowerShell is either wrong or misleading.
https://docs.microsoft.com/en-us/dotnet ... eckedItems
All controls are well documented on the Microsoft "docs" site and can be found by a simple search.
When trying to use forms it is critical that you reference the documentation to understand how to use a control. Much of the code you see on the Internet that is written with PowerShell is either wrong or misleading.
https://docs.microsoft.com/en-us/dotnet ... eckedItems
All controls are well documented on the Microsoft "docs" site and can be found by a simple search.
Re: How to run code in the powershell script for selected checkboxes
Hi jvierra,
I am not sure i quite understand what is going on in the link it seems like it is a C# language? also i ran some tests but i failed big time.
I am not sure i quite understand what is going on in the link it seems like it is a C# language? also i ran some tests but i failed big time.
Re: How to run code in the powershell script for selected checkboxes
The documentation for all things Forms is mostly in C#. It can help you to understand how these are intended to be used. Also the articles on the Sapien info site are helpful.
https://info.sapien.com/index.php/guis/gui-controls
Unfortunately the CheckedListBox has not been documented for PowerShell. You can use the ListBox docs to get background and then realize that it has a "CheckedItems" collection.
How to use forms in PowerShell requires that you have sufficient training in PowerShell to understand how to use the documentation.
https://info.sapien.com/index.php/guis/gui-controls
Unfortunately the CheckedListBox has not been documented for PowerShell. You can use the ListBox docs to get background and then realize that it has a "CheckedItems" collection.
How to use forms in PowerShell requires that you have sufficient training in PowerShell to understand how to use the documentation.
Re: How to run code in the powershell script for selected checkboxes
im sorry i cant find what i need, i give up.
Re: How to run code in the powershell script for selected checkboxes
The CheckedListBox has a property called "CheckedItems". This contains all checked items as an array. You have to enumerat3e this array and handle each check item separately.
I also wonder why you are using a VB input box when you can easily add a textbox to the form. Also the processing should be don in the form and not after it closes.
I suggest starting over and try to state simply and clearly what you want to accomplish and then create the code that does that.
I also wonder why you are using a CheckedListBox which is designed to select multiple items for code that only wants one item. A ComboBox is the correct control for that use case.
Code: Select all
foreach($item in $checlListBox.CheckedItems){
#process the item
Write-Host $item
}
I suggest starting over and try to state simply and clearly what you want to accomplish and then create the code that does that.
I also wonder why you are using a CheckedListBox which is designed to select multiple items for code that only wants one item. A ComboBox is the correct control for that use case.