Customize SharePoint site Users permissions SharePoint Group


Following Script will show you how to Add users to SharePoint online with SharePoint group from the CSV file. with customizing SharePoint site permissions.

And will be used to track whether users is available or not if users are not will saved a log file for reference

sample CSV file is shown below.

Prepare csv. file as shown below.


URL usersgroup email xxxxxxx Owners xxxxxxx Owners xxxxxxx Owners



        Write-host "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" -ForegroundColor White  
        $adminUrl = Read-Host "Please enter the Admin URL"        
        $User     = Read-Host "Please enter the Admin Username"         
        $pwd      = Read-Host "Please enter the password for $($User)" -AsSecureString  
                    Read-Host "Press Enter to Select Input File" 
        $path = Get-fileName($selectDirectory) 
        Write-host "Seleted File Path" $path 
        Write-host "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" -ForegroundColor White  
        $enddate = (Get-Date).tostring("yyyyMMddThhmmssZ"import-csv -Path $path  |  
ForEach-Object { 
$SiteURL = $_.URL 
$spuser =  $ 
        $cred1 = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $User$pwd  
        Connect-SPOService -Url $adminUrl -Credential $Cred1 
        Add-SPOUser -Site $SiteURL -Group $GroupName -LoginName $   
        write-host  $  " Added to "  $_.usersgroup -ForegroundColor Green 
            $_.Exception.Message | out-file "c:\$enddate.error.txt" -Append 
Function Get-fileName($selectDirectory) 
    [System.Reflection.Assembly]::LoadWithPartialName(""| Out-Null 
    $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog 
    $OpenFileDialog.initialDirectory = $initialDirectory 
    $OpenFileDialog.filter = "CSV (*.csv)| *.csv" 
    $OpenFileDialog.ShowDialog() | Out-Null