Get multiple Items from ListBox. How? RRS feed

  • Question

  • Hey Guys,

    I'm a total newbie in Powershell and I'm working on a script to add Users with selected groups to Active Directory.
    I was able to get the user creation to work but I'm struggling with multiple selections from a Listbox atm.
    I want to put users in one or more groups so I created a Listbox.

    By buttonclick "Create this User" it should create the user (Name, GivenName, Surname, EmailAdress, DisplayName, UserPrincipalName, SamAccountName, AccountPassword, Path) which works perfectly fine already.
    But I don't know how to get the selections of the Listbox to use the selections with "Add-AddGroupMember <Groups> -members $samname)".

    How can I do this?

    Monday, August 7, 2017 12:29 PM

All replies

  • Post your code?
    Monday, August 7, 2017 1:23 PM
  • [void] $listbox.Items.Add("1")
    [void] $listbox.Items.Add("2")
    [void] $listbox.Items.Add("3")
    [void] $listbox.Items.Add("4")

    New-ADUser -Name $fullname -GivenName $name -Surname $surname ...
    Add-ADGroupMember <The selected groups> - members $samname 
    I can select multiple Items from the listbox I want to add the user to all selected groups
    Monday, August 7, 2017 1:59 PM
  • Monday, August 7, 2017 2:01 PM
  • Hi,
    Just checking in to see if the information provided was helpful. Please let us know if you would like further assistance.

    Best Regards,


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Wednesday, September 6, 2017 7:36 AM