concept membership in category powershell

appears as: membership, membership
PowerShell in Practice

This is an excerpt from Manning's book PowerShell in Practice.

The GroupPrincipal class contains methods for modifying the membership of a group. By now, you should see a pattern emerging for how these scripts work. Listing 5.5 demonstrates this pattern. Load the assembly , set the context to the local machine , set the method to find the group , and then find the GroupPrincipal .

Listing 5.5. Modify local group membership

The group has a collection of members and we can use the Add() method to modify the membership . Note that we have to give the context and how we’re identifying the user as well as the user account to add. A final Save() and our changes are written back to disk.

Congratulations! You now understand recursion, as the function will keep calling itself as many times as necessary. As the array we created to hold the membership is global in scope, it can be accessed through the various levels of recursion.