Wednesday, May 25, 2011

Adding user to a site using PowerShell

Started exploring the PowerShell commands on SharePoint 2010.

New-SPUser command is used to add user to the site.

Below script gets the .csv file as input parameter which contains the URL, domain account, permission level.

AddUsers.PS1
-----------------------------------------
param(
[String]$InputFile = ""
)

$SitesList = Import-CSV $InputFile;

ForEach ($s in $SitesList)
{
$web = Get-SPWeb -identity $s.URL;

New-SPUser $s.Useraccount -web $web -PermissionLevel $s.Permission -confirm:$false;

$web.Dispose();
}

"Complete";
-----------------------


Sites.csv
----------
URL,Useraccount,Permission
http://test.com/sites/xyz,domain\user1,Contribute
-----------

To run the command
PS> AddUsers.PS1 -InputFile Sites.csv

Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home