Tuesday, June 23, 2015

Powershell to get all users in Owners group of site collection and sub-sites

If you want to get the users name, information for all the owners in a site collection and export it to an excel sheet, follow the below powershell script to do that:-
-------------------------------------------------------------------------------------------------------
Add-PsSnapin Microsoft.SharePoint.PowerShell


Start-SPAssignment -Global


Get-SPSite http://yoursite/
Get-SPWeb -Limit All |
  where { $_.HasUniquePerm -and $_.AssociatedOwnerGroup -ne $null } |
  foreach { $TTNweburl = $_.Url; $_ } |
  Select -ExpandProperty AssociatedOwnerGroup |
  Select -ExpandProperty Users |
  Select {$TTNweburl}, UserLogin, DisplayName | Export-Csv -Path d:\output.csv -Encoding         ascii -NoTypeInformation

Stop-SPAssignment -Global
----------------------------------------------------------------------------------------------------------------
above script will list all the users and save the output in a csv file in provided location.
Text in bold above needs to be changed with your environment changes.

No comments:

Post a Comment