The code in powershell:

 

Get-Content ‘gebruikers.txt’ | ForEach-Object { Add-ADGroupMember -Identity ‘G_Group_to_add_members’ -Members $_ }

 

This one-liner works as follows:

  1. Get-Content 'gebruikers.txt': This command reads the contents of the file ‘gebruikers.txt’. Each line in this file should ideally contain a username that you want to add to a specific group.
  2. Pipe (|): The output of Get-Content, which in this case is the list of usernames, is piped to the next command.
  3. ForEach-Object { ... }: This part of the command iterates over each username in the list. For each username ($_ represents the current item in the list), the enclosed command is executed.
  4. Add-ADGroupMember -Identity 'G_Group_to_add_members' -Members $_: This command adds the current username to the Active Directory group identified by ‘G_Group_to_add_members’. The -Members $_ part specifies that the current username from the list should be added to the group.

In summary, this one-liner reads usernames from ‘gebruikers.txt’ and adds each of them to the Active Directory group ‘G_Group_to_add_members’. It is efficient for batch adding users to a group, automating what would otherwise be a repetitive task.