Checkedlistbox Items

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 6 years and 6 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
dank42
Posts: 61
Last visit: Tue Apr 26, 2022 7:49 am

Checkedlistbox Items

Post by dank42 »

Hi,

I have a checkedlistbox which displays all the AD Groups that a user is a member of...each checked AD Group is removed from the user.

How can I write each checked item in the checkedlistbox to a textbox?

I use a richtextbox for logs, which are saved to a plain txt file. I would like to include the selected items from the checkedlistbox into the richtextbox for the logs.

Code: Select all

$ADGroups = Get-ADPrincipalGroupMembership -Identity $ADUser | Select-Object Name -ExpandProperty Name

Update-ListBox $checkedlistbox_ADGroups $ADGroups

foreach ($group in $checkedlistbox_ADGroups.CheckedItems)
		{
			
			Remove-ADPrincipalGroupMembership -Server $DC -Identity $ADUser -MemberOf $group.ToString() -Confirm:$false
			
		}
Attachments
Checkedlistbox.JPG
Checkedlistbox.JPG (18.84 KiB) Viewed 1843 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Checkedlistbox Items

Post by jvierra »

Just use "CheckedItems" and add them to the textbox.

$textbox.Lines += $CheckedListBox.CheckedItems

or in the loop:
$textbox.Lines += $group
User avatar
dank42
Posts: 61
Last visit: Tue Apr 26, 2022 7:49 am

Re: Checkedlistbox Items

Post by dank42 »

Nice one, thank you.
This topic is 6 years and 6 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