Quantcast
Channel: SharePoint Diary
Viewing all articles
Browse latest Browse all 1058

Import Users from Excel (CSV) to SharePoint using PowerShell

$
0
0
Requirement: Import list of users from Excel .CSV file to SharePoint and add them into appropriate groups.

Solution: Lets import users from Excel to SharePoint using PowerShell. Here is my CSV file with list of users and their target groups in SharePoint:
sharepoint import users from excel csv

PowerShell script to Import users from CSV to SharePoint 2013:
Add-PSSnapin Microsoft.SharePoint.PowerShell –erroraction SilentlyContinue

#Variables
$UserListCSV = "C:\UsersToImport.csv"
$SiteURL ="http://Sales.Crescent.com"

# Import the CSV file
$UserList = Import-CSV $UserListCSV #-header("GroupName","UserAccount") - If CSV doesn't has headers

#Get the Web
$Web = Get-SPWeb $SiteURL

#Iterate through each user from CSV file
foreach ($user in $UserList)
{
#Get the Group and User
$Group = $web.SiteGroups[$User.GroupName]
$User = $web.Site.RootWeb.EnsureUser($User.UserAccount)
#Add user to Group
$Group.AddUser($User)

Write-Host "$($User) Added Successfully!" -ForegroundColor Green
}

#Dispose web object
$Web.Dispose()

Viewing all articles
Browse latest Browse all 1058

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>