Powershell- Create a group & Change the owner of an existing SharePoint group

  1. $url = "http://urltoweb"  
  2. $GroupName = "Enter the Group Name"  
  3. $GroupOwner1 = "SharePoint Admins"  
  4. $GroupOwner2 = $GroupName+" Security Admin"  
  5. $SPSite = New-Object Microsoft.SharePoint.SPSite($url)  
  6. $OpenWeb = $SPSite.OpenWeb()  
  7. $OpenWeb.SiteGroups.Add($GroupName+" Designers",$OpenWeb.SiteGroups[$GroupOwner1],$OpenWeb.SiteUsers[""],"Members of this group can edit lists, document libraries, and pages in the site. Designers can create Master Pages and Page Layouts in the Master Page Gallery and can change the behavior and appearance of each site in the site collection by using the master pages and CSS files.")  
  8. $OpenWeb.Update() $OpenWeb.Dispose() $SPSite.Dispose();  
  9. Modify the existing group and change the owner.  
  10. #Get the SPWeb  
  11. $web = Get-SPWeb http://urltoweb  
  12. #Get the Group  
  13. $group = $web.SiteGroups["Enter the Group Name"]  
  14. #Get the User  
  15. $user = $web.EnsureUser("domain\username")  
  16. #Assign that user as the owner  
  17. $group.Owner = $user  
  18. #Update the Group  
  19. $group.Update()