Wednesday 15 March 2017

Powershell script: bulk add users to SharePoint group

Note - You may need to check the Claims prefix



Here's the PowerShell:

<# Instructions:

Create a Users.txt in this format (all in one column):

    i:0#.w|domain\aparnis
    i:0#.w|domain\candlandan
    i:0#.w|domain\stivj001
    i:0#.w|domain\attaj001
    i:0#.w|domain\marchorovitz
    etc

Populate the variables

#>

## Adding snap-in
Add-PSSnapin "Microsoft.SharePoint.PowerShell"

# Variables

$group = "External Readers"
$loc = "C:\scripts"        
$Users = Get-Content "$loc\Users.txt"        
$web = Get-SPWeb -identity $siteCollUrl

# code

foreach ($User in $Users) {
    $web.EnsureUser($User)        
    Set-SPUser -Identity $User -Web $siteCollUrl -Group $group         
}

# Dispose the web object


$Web.Dispose()

No comments:

Post a Comment

SharePoint Information Architecture Diagram

Here is the template I use for Information Architecture designs. It's built using Mindjet and I flesh the nodes out with the low level d...