How to run code in the powershell script for selected checkboxes

Welcome Forums General PowerShell Q&A How to run code in the powershell script for selected checkboxes

Viewing 2 reply threads
  • Author
    Posts
    • #206427
      Participant
      Topics: 2
      Replies: 2
      Points: 29
      Rank: Member

      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: Solved thank you .

      • This topic was modified 3 months ago by Idler64.
    • #206529
      Participant
      Topics: 12
      Replies: 1622
      Points: 2,560
      Helping Hand
      Rank: Community Hero

      Just like you looped to get values from a CSV, you need to loop to get items from the listbox. Not tested, but try something like:

          $us = [Microsoft.VisualBasic.Interaction]::InputBox("Select Username", "User Name")
          
          $results = foreach ($si in $listBox.SelectedItem) {
              try {
                  
                  $params = @{
                      Name            = $si.Value
                      PermissionLevel = 'GpoApply'
                      TargetName      = $us
                      TargetType      = 'User'
                      Domain          = $Domain.Name
                      ErrorAction     = 'Stop'
                  }
      
                  Set-GPPermissions @params
      
              }
              catch {
                  'Ut oh. Issue setting GP Permission for {0}. {1}' -f $si, $_
              }
          }
      
    • #206610
      Participant
      Topics: 2
      Replies: 2
      Points: 29
      Rank: Member

      Hi Rob,

      I have tested your method and unfortunately, it returns no errors but does nothing in return.

Viewing 2 reply threads
  • The topic ‘How to run code in the powershell script for selected checkboxes’ is closed to new replies.