Siguiendo con la serie de posts sobre como trabajar con permisos y niveles de permisos haciendo uso del modelo de objetos en cliente, en esta ocasión os dejo como obtener el listado de grupos de SharePoint de un sitio de SharePoint Online utilizando PowerShell utilizando el modelo de objetos en cliente en lugar del comando Get-SPOSiteGroup.
1: ############################################################################################################################################
2: # Script that allows to get all the SharePoint groups in a SharePoint Online Site
3: # Required Parameters:
4: # -> $sUserName: User Name to connect to the SharePoint Online Site Collection.
5: # -> $sPassword: Password for the user.
6: # -> $sSiteCollectionUrl: SharePoint Online Site
7: ############################################################################################################################################
8:
9: $host.Runspace.ThreadOptions = "ReuseThread"
10:
11: #Definition of the function that gets all the SharePoint groups in a SharePoint Online site
12: function Get-SPOSharePointGroupsInSite
13: {
14: param ($sSiteColUrl,$sUsername,$sPassword)
15: try
16: {
17: Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green
18: Write-Host "Getting all Groups in a SharePoint Online Site" -foregroundcolor Green
19: Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green
20:
21: #Adding the Client OM Assemblies
22: Add-Type -Path "<CSOM_Path>\Microsoft.SharePoint.Client.dll"
23: Add-Type -Path "<CSOM_Path>\Microsoft.SharePoint.Client.Runtime.dll"
24:
25: #SPO Client Object Model Context
26: $spoCtx = New-Object Microsoft.SharePoint.Client.ClientContext($sSiteColUrl)
27: $spoCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($sUsername, $sPassword)
28: $spoCtx.Credentials = $spoCredentials
29:
30: #Root Web Site
31: $spoRootWebSite = $spoCtx.Web
32: #Collecction of Sites under the Root Web Site
33: $spoSites = $spoRootWebSite.Webs
34:
35: #Loading Operations
36: $spoGroups=$spoCtx.Web.SiteGroups
37: $spoCtx.Load($spoGroups)
38: $spoCtx.ExecuteQuery()
39:
40: #We need to iterate through the $spoGroups Object in order to get individual Group information
41: foreach($spoGroup in $spoGroups){
42: $spoCtx.Load($spoGroup)
43: $spoCtx.ExecuteQuery()
44: Write-Host $spoGroup.Title
45: }
46:
47: $spoCtx.Dispose()
48: }
49: catch [System.Exception]
50: {
51: write-host -f red $_.Exception.ToString()
52: }
53: }
54:
55: #Required Parameters
56: $sSiteColUrl = "https://<SPO_SiteUrl>"
57: $sUsername = "<SPOUserName>"
58: #$sPassword = Read-Host -Prompt "Enter your password: " -AsSecureString
59: $sPassword=convertto-securestring "<SPO_Password>" -asplaintext -force
60:
61: Get-SPOSharePointGroupsInSite -sSiteColUrl $sSiteColUrl -sUsername $sUsername -sPassword $sPassword
Podéis descargaros el script desde el siguiente enlace de la Galería de Scripts de TechNet: How to get all the SharePoint Groups in a SharePoint Online Site. Por supuesto, el resultado que se obtiene es el siguiente para un cierto sitio de SharePoint Online.
Referencias: