PowerShell to get the list of Full Control Users on SharePoint
To get the full control users of a particular list of sites, first save the list of sites in csv format as below:
Powershell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | Add-Type -Path "C:\Users\mayuresh\Desktop\Data\Old\Microsoft.SharePoint.Client.Runtime.dll" Add-Type -Path "C:\Users\mayuresh\Desktop\Data\Old\\Microsoft.SharePoint.Client.dll" #Add-PSSnapin Microsoft.Sharepoint.Powershell $admin = "mayuresh.joshi@myclassbook.com" ; $password = Read-Host 'Enter Password' -AsSecureString $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($admin, $password) Connect-SPOService -Url https: //myclassbook-admin.sharepoint.com -credential mayuresh.joshi@myclassbook.com #Setup the context $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($webURL) $ctx.Credentials = $Credentials [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 #get the items from CSV $inputFilePath = "D:\Mayuresh\MissingOwners\Book2.csv" $itemCol = Import-Csv $inputFilePath $lists = $ctx.web.Lists $list = $lists.GetByTitle( "SiteUrls" ) $ExslistItems = $list.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery()) $ctx.load($ExslistItems) $ctx.executeQuery() ForEach($EstlistItem in $ExslistItems) { $list.GetItemById($EstlistItem.Id).DeleteObject() $ctx.executeQuery() } Write-Host $itemCol -ForegroundColor Cyan ForEach ($item in $itemCol) { $siteURL = $item.SiteUrls Write-Host $siteURL -ForegroundColor Cyan #Get all Groups from the site permissions $sitegroups = Get-SPOSiteGroup -Site $siteURL #Get Group info and members that have site owners permissions foreach ($sitegroup in $sitegroups) { #$i = 0 foreach($role in $sitegroup.Roles) { try { if ( $role.Contains(“Full Control”) ) { $listItemInfo = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation $listItem = $list.AddItem($listItemInfo) $listItem[ "Title" ] = $siteURL Write-Host $sitegroup.Title -ForegroundColor “Yellow” Write-Host $sitegroup.Users -ForegroundColor “Blue” foreach($user in $sitegroup.Users) { $listItem[ "FullControlUsers" ]=$listItem[ "FullControlUsers" ]+ "; " +$user; } $listItem[ "FullControlUsers" ]=$listItem[ "FullControlUsers" ].TrimStart( '; ' ); $listItem.Update(); $ctx.executeQuery() } } catch { write-host "$($_.Exception.Message)" -foregroundcolor red } } } } |
Download: GetFullControlUsers
0 Comments