How to import users from CSV to SharePoint site using PowerShell

Advertisement
Here we are showing how to import users from csv to SharePoint site using PowerShell, In some cases we have users available in the document or in notepad, we have to add those users into SharePoint group, adding 2 or 3 users manually is not a problem but adding 50+ users it will take lot of effort for a user to add in to SharePoint site.


For this using PowerShell we can add it easily, check the below code snippet and excel with CSV format looks.

Add-PSSnapin Microsoft.SharePoint.PowerShell
$UserinfoCSV = "C:\DotNetSharePoint\ImportUsers.csv"
 # Import the CSV file
#In CSV there are no headers,CSV having two columns values  one is SP group name and another one is username.
$UserInfo = Import-CSV $UserinfoCSV -header("GroupName","UserAccount")
#Get the Web
$Web = Get-SPWeb http://dotnetsharepoint.com/sites/sharepoint/importusers
 #looping each user from CSV file
foreach ($user in $UserInfo)
{
       $Group = $web.SiteGroups[$User.GroupName]
    $User = $web.Site.RootWeb.EnsureUser($User.UserAccount)
    $Group.AddUser($User)
     }
 $Web.Dispose()


SharePoint Online Real Time Training Contact: JLAKSHMITULASI@GMAIL.COM
Advertisements
SHARE

Lakshmi Tulasi Jasti

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

1 comments:

  1. Developed by Intuit, it is used to write user's financial data into a text format. excel dashboard software

    ReplyDelete