Permissions(Add/remove) to a sharepoint site

Glenn Maxwell 10,551 Reputation points
2020-09-09T20:38:04.433+00:00

Hi All

i have share point site to an office 365 unified group, how do i export the users from the below groups to a csv file.

Office 365 group owners
Additional Admins
Site Owners
Site members

if i need to add or remove a user from Site Owner/Site members/Additional Admins/Office 365 group owners from powershell how do i do it. experts guide me on this.

Microsoft Office Online Server
Microsoft Office Online Server
Microsoft on-premises server product that runs Office Online. Previously known as Office Web Apps Server.
607 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,025 questions
{count} votes

Accepted answer
  1. Jerry Xu-MSFT 7,936 Reputation points
    2020-09-10T06:10:49.743+00:00

    For getting these different user group members, it may better for you to use PowerShell in SharePoint Online Management Tool.

    $AdminCenterURL = "https://domain-admin.sharepoint.com/"  
    
    $siteURL="https://domain.sharepoint.com/sites/SiteName"    
    #Get Credentials to connect  
    $Cred = Get-Credential  
    
    #Connect to SharePoint Online and Azure AD  
    Connect-SPOService -url $AdminCenterURL -Credential $Cred  
    Connect-AzureAD -Credential $Cred | Out-Null  
    $Site = Get-SPOSite -Identity $siteURL  
    
    
    #Get Unified Group Owner  
    Get-AzureADGroupOwner -ObjectId $Site.GroupID | Select -Property DisplayName,UserPrincipalName  
    
    
    
    #use Pnp to get site collection admin, which is the additional admin  
    Connect-PnPOnline -Url $Site.Url -Credentials $Cred  
    Get-PnPSiteCollectionAdmin | Select -Property LoginName, Email   
    
    #get the site owner gruop members and site member group members  
    Get-SPOSiteGroup -Site $siteURL | where {$_.LoginName -like "<GroupName>*" }|select -Property LoginName,Users   
    

    As they are in different format, it may be better for you to get all the required properties and format them before you export to .csv file.

    The last part i use {$_.LoginName -like "<GroupName>*" } as the group-connect site has groups like <GroupName> Owners/members, remember to change that part with the name in your site.

    For add and remove user from these groups, here are the cmdlets you can use.

    Add-AzureADGroupOwner (Add Unified Group Owner)
    Remove-AzureADGroupOwner

    Add-PnPSiteCollectionAdmin (Add site collection administrator)
    Remove-PnPSiteCollectionAdmin

    Add/Remove user from group:
    Add-SPOUser
    Remove-SPOUser

    Example:https://www.sharepointdiary.com/2016/01/sharepoint-online-remove-user-from-group-using-powershell.html


    If the answer is helpful, please click Accept Answer and upvote it.
    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