Add-PSSnapin Microsoft.SharePoint.PowerShell
Function AddUsers($userArray, $webUrl, $group)
{
foreach ($user in $userArray)
{
$username = $user[0];
##Set-SPUser -Identity $username -Web $webUrl -Group $group
#Get the site name to the variable
$web = Get-SPWeb $webUrl
#Get the group name to the variable
$groupName = $web.SiteGroups[$group]
#Assign user to variable
$user = $web.Site.RootWeb.EnsureUser($username)
#Add user to group
$groupName.AddUser($user)
Write-Host -ForegroundColor green "User Added Successfully"
}
}
$userArray = @(
@("scu\JCharlton"),
@("scu\BHerring"),
@("scu\MGranger"),
@("scu\CHenson"),
@("scu\DRutledge"),
@("scu\JMcDougal"),
@("scu\DJackson"),
@("scu\SRichardson"),
@("scu\Brame")
)
#Call function without brackets
AddUsers $userArray "http://scushp01/IT/Projects/2016TS" "2016 Technical Support Members"
AddUsers $userArray "http://scushp01/IT/Projects/2016IF" "2016 Infrastructure Members"
AddUsers $userArray "http://scushp01/IT/Projects/2016Dev" "2016 Development Members"