in the below PowerShell script I want to get the permissions assigned to the users. $spgroup.roles is not displaying anything. Can any one help me on this,

#Add - PSSnapin Microsoft.SharePoint.PowerShell

$host.Runspace.ThreadOptions = "ReuseThread" 

Function Get-SiteGroup-Owners 
    param ($sCSOMPath,$sSiteUrl,$sUserName,$sPassword,$FileName) 
        $sCSOMRuntimePath=$sCSOMPath +  "\Microsoft.SharePoint.Client.Runtime.dll"         
        $sCSOMPathdll=$sCSOMPath +  "\Microsoft.SharePoint.Client.dll"              
        Add-Type -Path $sCSOMPathdll          
        Add-Type -Path $sCSOMRuntimePath        

        #SPO Client Object Model Context 
        $spoCtx = New-Object Microsoft.SharePoint.Client.ClientContext($sSiteUrl) 
        $spoCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($sUserName, $sPassword)   
        #$spoCredentials = New-Object System.Net.NetworkCredential($sUserName, $sPassword)    # for on premise
        $spoCtx.Credentials = $spoCredentials        

        $web = $spoCtx.Web
        $spGroups =$web.SiteGroups


        Write-Host "Groups Count= $($spGroups.Count)"

        foreach($spGroup in $spGroups)
            $site =@()
            $users = $spGroup.Users

            foreach($spUser in $users)

                    $site += New-Object -TypeName PSObject -Property @{
                                    SiteUrl =$sSiteUrl
                                    GroupName = $spGroup.Title
                                    PrincipalType= $spGroup.Roles
                                    User =$spUser.LoginName
                                    UserEmail =$spUser.Email
                                    } | Select  SiteUrl,GroupName,PrincipalType,User,UserEmail

                          Write-Host "This is test" $.Roles

                catch [System.Exception] 
                    Write-Host -ForegroundColor Red $_.Exception.ToString()    

            Write-Host $sCSOMPath

           # $site| Export-CSV ($sCSOMPath+"\"+$FileName+".csv") -NoTypeInformation -Append #-Encoding UTF8          


        Read-Host -Prompt "file created Successfull..! in the following path $sCSOMPath, Press any key to close this window"

    catch [System.Exception] 
        Write-Host -ForegroundColor Red $_.Exception.ToString()    
        Read-Host -Prompt "Operation failed..! Press any key to close this and re run the script"

$FileName= "SiteCollection_Group_Members"          
$sSiteUrl = "https://mysite.test.com"  
$sUserName = "admin@micrososft.com" 
$sPassword = ConvertTo-SecureString "Password" -AsPlainText -Force 

$scriptpath = $MyInvocation.MyCommand.Path
$dir = Split-Path $scriptpath

Write-Host "Getting Site Collection group Members"
Write-Host "-----------------------------------" 
Get-SiteGroup-Owners -sCSOMPath $dir -sSiteUrl $sSiteUrl -sUserName $sUserName -sPassword $sPassword  -FileName $FileName
  • There is no Roles property on the SPGroup object. See msdn.microsoft.com/en-us/library/… – Bunzab Jul 17 '17 at 9:50
  • Permissions are bound to objects. You need to get the object, be it a site, list or item and then query the roleassignments and you can get roledefinitionbindings from that. I can put up some sample code later if you need. – Bunzab Jul 17 '17 at 10:46
  • bunzab can you please provide a sample if you have any. That will really help me up – santosh kondapalli Jul 17 '17 at 13:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.