About Sharepoint

jennyKim 240 Reputation points
2023-06-14T11:14:11.9066667+00:00

I tried and now i can able to grant permission to user like Read, Edit

But the problem is after granting permission how ca i remove through powershell?

I search for everywhere but not found any script

As well as Cannot i grant permission through CSV so it doesnot took time

If you know the answer it will be helpful for me

Thank you

Microsoft 365 and Office | SharePoint Server | For business
Microsoft 365 and Office | Install, redeem, activate | For business | Windows
Microsoft 365 and Office | SharePoint | For business | Windows
Microsoft 365 and Office | SharePoint Server | Development
0 comments No comments
{count} votes

Answer accepted by question author
  1. Xyza Xue_MSFT 30,241 Reputation points Microsoft External Staff
    2023-06-15T03:01:09.8466667+00:00

    Hi @jennyKim ,

    Remove user from site collection using PowerShell in SharePoint Online, Please use the following code:

    #Config Variables
    $SiteURL = "SiteURL"
    $UserID="i:0#.f|membership|******@domain.onmicrosoft.com"
     
    #Connect to PnP Online
    Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
     
    #sharepoint online powershell delete user from site collection
    Remove-PnPUser -Identity $UserID -Force
    

    User's image

    Bulk Add Users and Groups from a CSV File to SharePoint Online Sites, Please use the following code:

    1.Create a CSV file and fill it (The content requirements are as follows) , then Format as Table .

    User's image

    #Config Variables
    $CSVPath = "C:\Temp\UsersAndGroups.csv"
     
    #Get Data from CSV
    $CSVData =  Import-CSV -Path $CSVPath
     
    Try {
        ForEach($Row in $CSVData)
        {
            #Connect to the Site with PnP PowerShell
            Connect-PnPOnline -Url $Row.SiteURL -Interactive
          
            #Check if the group exists already
            If((Get-PnPGroup | Where { $_.Title -eq $Row.GroupName}) -eq $Null)
            {
                #Create SharePoint Online Group
                $Group = New-PnPGroup -Title $Row.GroupName -ErrorAction Stop
                Write-Host -f Green "Group '$($Row.GroupName)' Created Successfully!"
            }
            Else
            {
                #Get the Group
                $Group = Get-PnPGroup -Identity $Row.GroupName
            }
            #Set Group Permissions
            Set-PnPGroupPermissions -Identity $Group -AddRole $Row.Permission
     
            #Add Users to the Group
            $Users =  $Row.Users -split ";"
            ForEach($User in $Users)
            {
                $NewUser = Add-PnPGroupMember -LoginName $User.Trim() -Identity $Group
                Write-host -f Green "`tAdded $User to $($Group.Title)"
            }
        }
    }
    Catch {
        write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
    }
    
    

    Reference: https://www.sharepointdiary.com/2021/02/sharepoint-online-add-bulk-users-and-groups-using-powershell.html


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.