I have a very large and complex SharePoint 2016 site with hundreds of groups. I'm writing a powershell script to add a specific user to a group if the group's name matches some text.
For example, I need to add UserX to any group that has the word "English" in the name of the group.
I have the following code working to add to the user to an individual group, but not sure how to loop through and add them only when the partial text matches.
$site=get-spsite https://site #get web object $web=$site.RootWeb #Enumarate site groups $web.SiteGroups |select name #get user object $user=$web.EnsureUser("domain\user") #Get group object $group=$web.SiteGroups["Year 10 ENGLISH Staff"] #add user to group $group.AddUser($user)
Thanks for any help