0
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

#Using Get-SPSite 
function global:Get-SPSite($url)
 {
    return new-Object Microsoft.SharePoint.SPSite($url)
 }

function global:Get-SPWeb($url)
{
  $site= New-Object Microsoft.SharePoint.SPSite($url)
        if($site -ne $null)
            {
               $web=$site.OpenWeb();      
            }
    return $web
}

$URL="http://u************"

     $site = Get-SPSite $URL

     #Write the Header to "Tab Separated Text File"
        "Site Name`t  URL `t Group Name `t User Name" | out-file "C:\Users\s-US_SC_SSPDev_Admin\Documents\VenuPscripts\CSVFiles\test5.csv"

     #Iterate through all Webs
      foreach ($web in $site.AllWebs)
      {
        Write-Host "Site: ":$web -ForegroundColor Red;
        #Write the Header to "Tab Separated Text File"
        "$($web.title) `t $($web.URL) `t  `t  `t `t " | out-file "C:\Users\s-US_SC_SSPDev_Admin\Documents\VenuPscripts\CSVFiles\test5.csv" -append

         $siteUsers = $web.SiteUsers
         $siteUsers.Count

            #Write-Host "SiteUsers: ":$siteUsers -ForegroundColor red;
         foreach($user in $siteUsers) 
            {  
                #Exclude Built-in User Accounts
                if(($User.LoginName.ToLower() -ne "nt authority\authenticated users") -and ($User.LoginName.ToLower() -ne "sharepoint\system") -and ($User.name.ToLower() -ne "Everyone") -and ($User.LoginName.ToLower() -ne "nt authority\local service"))
                {



                            $permissionInfo = $web.GetUserEffectivePermissionInfo($user.name)
                            $roles = $permissionInfo.RoleAssignments
                            #write-host "Now checking the permissions of the user "  $user  " " "in the site " $web.Url
                        for ($i = 0; $i -lt $roles.Count; $i++)
                        {
                            $bRoles = $roles[$i].RoleDefinitionBindings
                            foreach ($roleDefinition in $bRoles)
                            {
                                 if ($roles[$i].Member.ToString().Contains('\'))
                                {
                                "`t  `t  `t  $($user.name)" | out-file "C:\Users\s-US_SC_SSPDev_Admin\Documents\VenuPscripts\CSVFiles\test5.csv" -append 

                                write-host "The User "  $user  " has direct permissions "  $roleDefinition.Name
                                }

                            }


                        }
                    }

            }                            



             #Get all Groups and Iterate through   
             foreach ($group in $Web.groups)
             {                    

             #Write-Host "Groups: ":$group -ForegroundColor green;
                    "`t  `t $($Group.Name) `t   `t `t " | out-file "C:\Users\s-US_SC_SSPDev_Admin\Documents\VenuPscripts\CSVFiles\test5.csv" -append
                    #Iterate through Each User in the group
                           foreach ($user in $group.users)
                            {
                            #Write-Host "Groups: ":$user -ForegroundColor white;
                               #Exclude Built-in User Accounts
                        #if(($User.LoginName.ToLower() -ne "nt authority\authenticated users") -and ($User.LoginName.ToLower() -ne "sharepoint\system") -and ($User.LoginName.ToLower() -ne "nt authority\local service"))
                        #{
                                    "`t  `t  `t  $($user.name)" | out-file "C:\Users\s-US_SC_SSPDev_Admin\Documents\VenuPscripts\CSVFiles\test5.csv" -append
                       #  }
                            }
             }


       }

    #write-host "Report Generated at C:\Users\s-US_SC_SSPDev_Admin\Documents\VenuPscripts\CSVFiles\test5.csv"

am facing this error

Exception calling "GetUserEffectivePermissionInfo" with "1" argument(s): "The user does not exist or is not unique." At C:\Users\s-us_sc_drspint_farm\Videos\get_users.ps1:49 char:14 + $permissionInfo = $web.GetUserEffectivePermissionInfo($AddUSername) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : SPException –

  • am facing this error ********************** Exception calling "GetUserEffectivePermissionInfo" with "1" argument(s): "The user does not exist or is not unique." At C:\Users\s-us_sc_drspint_farm\Videos\get_users.ps1:49 char:14 + $permissionInfo = $web.GetUserEffectivePermissionInfo($AddUSername) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : SPException – Venu Feb 20 '18 at 14:37
0

This script helps you to get the users by groups in a SharePoint site collection,

 $site = Get-SPSite <Provide Site Collection URL here>
        $web = $site.OpenWeb()
        $groups = $web.sitegroups

        foreach ($grp in $groups) {
            "Group: " + $grp.name;
            $groupName = $grp.name
            write-host "Group: " $groupName   -foregroundcolor green
            foreach ($user in $grp.users) {
                    "User: " + $user.name
                    write-host "User " $user.UserLogin   -foregroundcolor red
            }
        }
  • but i want based on each sub site loop in site collection. i should write sub site url . – Venu Feb 20 '18 at 14:46

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.