SharePointTechnicalSupport

SharePoint Technical Support Blog in SharePoint Online | office 365 | azure

  • Home
  • Home
  • Solutions
    • SharePoint Server
      • SharePoint 2010
      • SharePoint 2013
      • SharePoint 2016
      • SharePoint Online
      • CU Patch Update
    • Project Server
      • Project Server 2010
      • Project Server 2013
      • Project Server 2016
      • Project Server Online
      • CU Patch Update
        • PWA2016
          • DECEMBER
        • PWA2013
      • News Project Server
    • Workflow
      • Nintex
      • SharePoint Designer
    • PowerShell
    • Windows Server
      • IIS
      • DNS
      • Active Directory
      • Windows Server 2016 Networking
    • Cloud
      • Azure
      • Office 365
  • Download
    • SharePoint Tools
    • Patch Update
      • SharePoint Patch
      • Project Server Patch
        • PWA2016
          • December
      • Office Patch
    • White Papers
    • Webinar
    • Presentation
      • SharePoint 2013 PPT
    • Video
  • MSDN Links
    • SharePoint
      • Gallery
      • Wiki
      • Forum
    • Microsoft Tech Community
    • Microsoft Docs
    • Microsoft Learn
    • Roadmap
    • Azure Update
    • SharePoint Fest
    • IIS
    • ProjectServer
      • Forum
    • Powershell Gallery
      • Powershell Forum
    • Microsoft Partner
    • sharepoint best practices
  • Contact Me

Home › Active Directory › PowerShell Script to get all the Active Directory groups in your SharePoint Farm

PowerShell Script to get all the Active Directory groups in your SharePoint Farm

By Deviprasad Panda on 01/05/2015

At a client recently, I was tasked to create an inventory of all the Active Directory Groups that give access to a SharePoint site! I built it mostly from scratch, so here it is as well as some explanations to help you use it:

function WriteLogs ($message) {
$message | Out-File $logfile -append
}

$logfile = “C:ADGroupInventorygrouplist.txt”
Write-Host “Starting Group Script inventory”
$was = Get-SPWebApplication

foreach ($wa in $was)
{
$webappUrl = $wa.url
Write-Host “Starting to look in $webappUrl”
$spWebApp = Get-SPWebApplication $wa.url
foreach($site in $spWebApp.Sites)
{
$siteurl = $site.url
Write-Host “Going into SiteCollection $siteurl”
$group = $site.RootWeb.SiteUsers
foreach ($grp in $group)
{

Ensure the item is a domain group

if($grp.IsDomainGroup -eq “True”)
{
$groupname = $grp.name
WriteLogs “$groupname”
}
}
}
}

  • First of all, change the $logfile variable to a folder that exists to make sure the logs work.
  • Second, in the Central Administration, give yourself “Full Control” in the Web Application User Policy. This will make sure that you won’t have any access denied when you go through each and every site collection in your farm.

  • Afterwards, open SharePoint Management Shell as an Administrator, and run the script. Depending of the size of you farm, it shouldn’t take too long, and you should see progress of every site being scanned on the screen. At the end, you will have a text file looking like this:

PowerShell

PowerShell

You will notice in the screenshot that some group names are repeated, as well as some of them are in capital and some of them are lowercase.

  • So, I used NotePad++ to get all the unique group names!

First of all, go in Edit > Convert Case to > Upercase!

You will notice in the screenshot that some group names are repeated, as well as some of them are in capital and some of them are lowercase.

get all the Active Directory groups in your SharePoint Farm

get all the Active Directory groups in your SharePoint Farm

To get unique lines, you will need the TextFX plugin. This used to be included in older versions of Notepad++, but if you have a newer version, you can add it from the menu by going to Plugins -> Plugin Manager -> Show Plugin Manager -> Available tab -> TextFX -> Install. In some cases it may also be called TextFX Characters, but this is the same thing.

After the plugin is installed, go in TestFX Tools and check the “sort ascending” and “sort outputs only UNIQUE” lines. Afterwards, click the “Sort lines case insensitive at column”. (make sure that you do Ctrl+a in the file to select all the lines before clicking).

get all the Active Directory groups in your SharePoint Farm

get all the Active Directory groups in your SharePoint Farm

Now, your Notepad++ will only show the unique group names in your SharePoint Farm!

get all the Active Directory groups in your SharePoint Farm

get all the Active Directory groups in your SharePoint Farm

Drop a comment if this helped!

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on WhatsApp (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Pinterest (Opens in new window)

Related


‹ SharePoint 2013 Site Template ID List for PowerShell
500 Internal Server Error sharepoint2013 SSRS ›

Categories: Active Directory, powershell script, SharePoint 2013, User Profile, Userprofile

Tags: Active Directory, active-directory-group, Get list of all users, powershellscript, SharePoint 2013

My Book

  • 1 Deviprasad Panda

Follow Me

  • YouTube
  • LinkedIn
  • Facebook
  • Twitter

Category Cloud

administration Authentication Cache content databases Default Health IIS InstallationConfiguration Migration Monitoring Performance Permission powershell powershell command powershell script Search Service Application sharepoint2010 SharePoint 2013 SharePoint 2016 SharePoint 2019 sharepoint server SharePointTools Site site collection Template web application WebPart WebService

Top Posts & Pages

  • change maximum upload file size limit in sharepoint
    change maximum upload file size limit in sharepoint
  • SharePoint 2019 – TCP/IP Ports
    SharePoint 2019 – TCP/IP Ports
  • export import list library sites in sharepoint
    export import list library sites in sharepoint
  • Backup restore site collection sharepoint
    Backup restore site collection sharepoint
  • move site collection to dedicate content database
    move site collection to dedicate content database
  • sharepoint service instance start stop stuck
    sharepoint service instance start stop stuck
  • Managed path in sharepoint web application
    Managed path in sharepoint web application
  • 403 forbidden error fix
    403 forbidden error fix

Follow Blog via Email

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 775 other subscribers

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy

Contact Me

Bengaluru, India
support@spmcse.com
Everyday : 8 AM - 12 AM IST