Tag Archives: spgroup

Add SPUser to SPGroup using Powershell

Adding user to SharePoint group manually is a painful process. Not to mention if you have tons of users using your SharePoint site.  To make life easier, I actually came out with a simple powershell script and XML (where you store the user mappings) to automate the process.

$webUrl = Read-Host "Enter SharePoint Web URL"
if($webUrl -eq "")
 $webUrl = "[Your default http]";
$web = Get-SPWeb $webUrl
$xml = (Get-Content .\PumpUser.xml)
#Put your xml (in this case 'PumpUser.xml') in the same folder where you place your powershell script
foreach($group in $xml.Groups.Group)
 $title = $group.Title
 $spGroup = $web.SiteGroups[$title]
 foreach($user in $group.Users.User)
  $temp = $web.EnsureUser($user)
  Write-Host "Added "$temp" to "$spGroup.Name

The xml goes like this.

<?xml version="1.0" encoding="UTF-8"?>
  <Title>Administrator Group</Title>

Simple and easy =)