{"id":2214,"date":"2017-06-21T21:34:05","date_gmt":"2017-06-21T21:34:05","guid":{"rendered":"http:\/\/microsoftgeek.com\/?p=2214"},"modified":"2017-06-21T21:34:24","modified_gmt":"2017-06-21T21:34:24","slug":"find-empty-groups-in-active-directory-using-powershell","status":"publish","type":"post","link":"https:\/\/microsoftgeek.com\/?p=2214","title":{"rendered":"Find empty groups in Active Directory using PowerShell"},"content":{"rendered":"<p>Today we will find empty groups in Active Directory using Powershell. You all may know that we as System Administrators are required to create groups in the Active Directory for all sorts of purposes and reasons.<\/p>\n<p>But over time, do people who request for these groups really utilise them?<\/p>\n<div class=\"googlepublisherpluginad\"><\/div>\n<p>It is bound to happen that your domain will be filled with groups that have no members inside them because of various reasons. The person who requested for the group is no longer in the organization or group was created only for the testing purposes and you have not deleted them after the specified time.<\/p>\n<p>So we will finding out the empty groups with Powershell today, and trust me you will love how fast and easy it is. Imagine you had to check every group for its members manually? You would want to leave your job immediately &#x1f61b;<\/p>\n<p>So we have Powershell to our rescue. &#x1f609;<\/p>\n<p><code>Import-Module activedirectory<br \/>\nGet-ADGroup -Filter * -Properties Members | where {-not $_.members} | select Name | Export-Csv C:\\emptygroups.csv \u2013NoTypeInformation<\/code><\/p>\n<p>The above two lines of code will produce all the empty groups in your domain and export it to a csv file.<\/p>\n<p>Let us see what we are doing here.<\/p>\n<p>We first import the Active Directory Module into the Powershell console so that we can use AD related cmdlets.<\/p>\n<p>Next with the help of the Get-ADGroup cmdlet we are querying all the groups in the domain using the Filter parameter as <strong>any<\/strong>. We pipe that output to where-object and select the groups which has no members.<\/p>\n<p>Finally we pipe that to the Export-Csv cmdlet to see nicely in the csv file.<\/p>\n<p>We could select a lot more properties and output to the csv file by passing the Get-ADgroup cmdlet to Get-Member and finding the available properties associated with it!<\/p>\n<p>Get-ADGroup \u2018Finance Team\u2019 | Get-Member<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-578 no-display appear\" src=\"http:\/\/www.enterprisedaddy.com\/wp-content\/uploads\/2015\/02\/Untitled110.png\" alt=\"Find empty groups in Active Directory using PowerShell\" width=\"985\" height=\"349\" \/><\/p>\n<p>If you are working multi domain environment, then you can the below line to check empty groups in a different domain.<\/p>\n<p><code>Get-ADGroup -Filter * -Properties Members \u2013server DomainName:3268 | where {-not $_.members} | select Name | Export-Csv C:\\emptygroups.csv \u2013NoTypeInformation<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today we will find empty groups in Active Directory using Powershell. You all may know that we as System Administrators are required to create groups in the Active Directory for all sorts of purposes and reasons. But over time, do people who request for these groups really utilise them? It is bound to happen that [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[42,59],"tags":[],"class_list":["post-2214","post","type-post","status-publish","format-standard","hentry","category-ad","category-powershell"],"_links":{"self":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/2214","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2214"}],"version-history":[{"count":2,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/2214\/revisions"}],"predecessor-version":[{"id":2216,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/2214\/revisions\/2216"}],"wp:attachment":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2214"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2214"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}