This powershell script is used to export list of all users for a site present under different sharepoint groups.

Script:

PowerShell
Edit|Remove
$site = Get-SPSite <Provide Site Collection Url here> 
$web = $site.OpenWeb() 
$groups = $web.sitegroups 
 
foreach ($grp in $groups) { 
    "Group: " + $grp.name;  
    $groupName = $grp.name 
     
    foreach ($user in $grp.users) { 
            "User: " + $user.name 
            write-host "User " $user.UserLogin   -foregroundcolor red 
    } 
}
 

Usage: 

Navigate to script location and use below command -

GetUsers.ps1 | Out-File "Provide full file path here"

If file path is not provided, only file name is provided, then file is saved in same location of powershell script.