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
https://xxxxxxx.sharepoint.com/sites/xxxxxxxx xxxxxxx Owners xxxxxxxxx@xxxxxxx.xxx
https://xxxxxxx.sharepoint.com/sites/xxxxxxxx xxxxxxx Owners xxxxxxxxx@xxxxxxx.xxx
https://xxxxxxx.sharepoint.com/sites/xxxxxxxx xxxxxxx Owners xxxxxxxxx@xxxxxxx.xxx

 

 

PowerShell
Edit|Remove
clear 
 
        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 
$GroupName$_.usersgroup 
$PermissionLevel$_.Permission 
$spuser =  $_.email 
     
     
        $cred1 = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $User$pwd  
        Connect-SPOService -Url $adminUrl -Credential $Cred1 
        try{ 
        Add-SPOUser -Site $SiteURL -Group $GroupName -LoginName $_.email   
        write-host  $_.email  " Added to "  $_.usersgroup -ForegroundColor Green 
        } 
         Catch 
       {  
         
            $_.Exception.Message | out-file "c:\$enddate.error.txt" -Append 
        } 
          
        } 
 
 
 
Function Get-fileName($selectDirectory) 
{ 
    [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms"| Out-Null 
     
    $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog 
    $OpenFileDialog.initialDirectory = $initialDirectory 
    $OpenFileDialog.filter = "CSV (*.csv)| *.csv" 
    $OpenFileDialog.ShowDialog() | Out-Null 
    $OpenFileDialog.filename 
}