Quantcast
Channel: SharePoint 2010 - Setup, Upgrade, Administration and Operations forum
Viewing all articles
Browse latest Browse all 13778

Bulk upload users to sharepoint group

$
0
0

i tried to add users tru sharepoint 2013 powershell .bt it shows "the specific user is not found "..can anybody help me.below is my code

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
#Import the List of Users from a .csv file,
$UserListImport-CSV "C:\UserList.csv"
  
#Get the Web
$web = Get-SPWeb "http://site/"
  
foreach ($Row in $UserList)
{
  #Get the Group
   $Group $web.Groups[$Row.GroupName]
  
 #Validate the user name
 try
   {
        $user $web.Site.RootWeb.EnsureUser($Row.AccountName)
   }
   catch [system.exception]
   {
     write-host $_.Exception.Message
   }
  
   #Add user if valid user name is provided
    if($user -ne $null)
    {
       $Group.AddUser($user)
       write-host $user.AccountName
    }
}
 
#Dispose the web object
$Web.Dispose()



.
My CSV file has only AccountName and GroupName (AccountName in the format of: Domain\username)




Viewing all articles
Browse latest Browse all 13778

Latest Images

Trending Articles



Latest Images

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