Jan 6, 2013

Import Users from Excel to SharePoint using PowerShell

# Import the .csv file, and specify manually the headers, without column name in the file 
$userList=IMPORT-CSV C:\UserToUpload.csv -header("GroupName","UserName")

#Get the site name to the variable
$web = Get-SPWeb SiteURLHere

foreach ($user in $userList)
{
$groupName = $web.SiteGroups[$userList.group]
$user = $web.Site.RootWeb.EnsureUser($userList.user)
$groupName.AddUser($user)
}
Write-Host -ForegroundColor green "Users Added Successfully"
}
$Web.Dispose()

2 comments:

  1. Hi,

    My organization has recently moved from Sharepoint 2007 to 2013 - double hop attach upgrade method.

    I`ve successfully used this script in order to import users to SP groups. However, the interesting thing is that although the users are listed under the correct groups the permissions do not seem to be effective.

    To be more specific: for site A i have 3 groups: Owners / Members / Visitors. If i add via this script a user to any of the groups it wont have any "effective permissions" in site A. If i use the management GUI in order to add the user everything works as expected...

    What could be the reason behind this behavior?

    Y-nP

    ReplyDelete
  2. HI How to do it for a specific user. Will this be useful for SharePoint 2007

    ReplyDelete

Dear Readers,

I LOVE to hear from you! Your feedback is always appreciated. I will try to reply to your query as soon as possible.

1. Make sure to click the "Notify me" check box at the right side to be notified of follow up comments and replies.
2. Please Do Not Spam - Spam comments will be deleted immediately upon review.