none
Add multiple users to multiple site collections from csv or excel spreadsheet RRS feed

  • Question

  • Hello,

    I want to add multiple users to multiple site collections list that i have in excel spreadsheet. I don't want them to be added to all site collections under web applications. I have the list of specific site collections under same web application in excel and i want to add multiple users to that list of site collections. How can i achieve it in SharePoint 2013 using powershell?

    -CS


    chirag

    Wednesday, October 16, 2019 2:29 PM

All replies

  • Hi,

    You could check below PowerShell to add user to SharePoint for demo.

    Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
     
    #Import the List of Users from a .csv file,
    $UserList= Import-CSV "C:\UserList.csv"
      
    #Get the Web
    $web = Get-SPWeb "http://sharepoint.crescent.com/sites/marketing"
      
    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()

    https://www.sharepointdiary.com/2015/03/import-users-from-csv-file-to-sharepoint-using-powershell.html

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Thursday, October 17, 2019 8:04 AM
  • Hi,

    I am checking to see how things are going there on this issue. Please let us know if you would like further assistance.

    You can mark the helpful post as answer to help other community members find the helpful information quickly.

    You can also share your own solution here and mark it as answer, and we can learn from each other.

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Friday, October 25, 2019 9:17 AM
  • I need to provide access to specific site collections in excel spreadsheet under one web application for users. I have the list of site collections in excel where only i need to grant access to users (5-6 users). How can i achieve that?

    -CS


    chirag

    Friday, October 25, 2019 4:14 PM
  • Hi,

    Add a property to identify which user need to be imported, sample demo for your reference, you could try it.

    Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
     
    #Import the List of Users from a .csv file,
    $UserGroup= Import-Csv "C:\Lee\UserList.csv"|Group-Object Site
      
    foreach($Group in $UserGroup){
    	$site=$Group.Name            	
    	#Get the Web
    	$web = Get-SPWeb $site
    	foreach ($user in $Group.Group)
    	{
    		if($user.NeedImport -eq $true){
    		Write-Host $user.AccountName
    		#Get the Group
    	    $Group = $web.Groups[$user.GroupName]
    	  
    		 #Validate the user name
    		 try
    		   {
    		        $user = $web.Site.RootWeb.EnsureUser($user.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()
    }
    

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Monday, October 28, 2019 7:23 AM
  • Hi,
    I am checking to see how things are going there on this issue. Please let us know if you would like further assistance.
    You can mark the helpful post as answer to help other community members find the helpful information quickly. 
    You can also share your own solution here and mark it as answer, so it may help others who has similar requirement.
    Best Regards,
    Lee

    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Thursday, October 31, 2019 2:57 AM
  • I did exactly same as mentioned, but did not work. I manually have to grant access to 5-6 users to each site collection. 

    chirag

    Thursday, October 31, 2019 2:15 PM
  • Hi ,

    Try below updated script.

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

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Friday, November 1, 2019 1:32 AM