I need powershell snippet to get site the owner name and email details only from default site owner group

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

Add-Type -AssemblyName System.DirectoryServices.AccountManagement



$ct = [System.DirectoryServices.AccountManagement.ContextType]::Domain

$ctx = New-Object 'DirectoryServices.AccountManagement.PrincipalContext' ([DirectoryServices.AccountManagement.ContextType]::Domain)
$site = get-spweb "xxxxxx"

$groups = $site.Groups | where {$_.Name -eq $site.Title+" Owners"}
$user = @()
foreach($grp in $groups)

        $user = Get-SPUser -Web $site -Group $grp 
        write-host $user.name  "`t" $user.LoginName "`t"  $user.Email

Use the PowerShell script below:

$web = Get-SPWeb "http://sp"
$sitegroup =$web.SiteGroups |?{$_.Name -EQ "SP Owners"}
foreach($user in $sitegroup.users) {
 "$($user.displayname) `t $($user.LoginName) `t $($user.Email) " | out-file C:\groupmembersreport.csv -append
| improve this answer | |

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.