{"id":499,"date":"2014-06-10T13:46:00","date_gmt":"2014-06-10T03:46:00","guid":{"rendered":"http:\/\/threemillion.net\/blog\/?p=499"},"modified":"2014-06-10T13:46:00","modified_gmt":"2014-06-10T03:46:00","slug":"get-group-membership-of-an-ad-user","status":"publish","type":"post","link":"https:\/\/threemillion.net\/blog\/?p=499","title":{"rendered":"Get group membership of an AD User"},"content":{"rendered":"<p>Why is it that I cannot seem to see the groups a user is a member of when I use the Get-ADUser cmdlet?<br \/>\nSurely this a very common question.<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\nPS &gt;$thisuser = Get-ADUser -Filter 'Name -like &quot;LogonID&quot;'\r\nPS &gt;$thisuser\r\n\r\nDistinguishedName  : CN=LogonID,OU=Users,DC=Home,DC=local\r\nEnabled            : True\r\nGivenName          : John\r\nName               : LogonID\r\nObjectClass        : user\r\nObjectGUID         : 9383f28b-e4fc-4a8e-81e4-73094d4bba63\r\nPSShowComputerName : {}\r\nSamAccountName     : LogonID\r\nSID                : S-1-5-21-9871330858-2016497126-1624845914-51132\r\nSurname            : Doe\r\nUserPrincipalName  : LogonID@home.local\r\nWriteErrorStream   : {}\r\nPropertyNames      : {DistinguishedName, Enabled, GivenName, Name...}\r\nPropertyCount      : 12\r\n<\/pre>\n<p>Let us try get-member<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\nPS &gt;$thisuser | Get-Member\r\n\r\n   TypeName: Microsoft.ActiveDirectory.Management.ADUser\r\n\r\nName               MemberType            Definition\r\n----               ----------            ----------\r\nContains           Method                bool Contains(string propertyName)\r\nEquals             Method                bool Equals(System.Object obj)\r\nGetEnumerator      Method                System.Collections.IDictionaryEnumerator GetEnumerator()\r\nGetHashCode        Method                int GetHashCode()\r\nGetType            Method                type GetType()\r\nToString           Method                string ToString()\r\nItem               ParameterizedProperty Microsoft.ActiveDirectory.Management.ADPropertyValueCollection Item(string ...\r\nDistinguishedName  Property              System.String DistinguishedName {get;set;}\r\nEnabled            Property              System.Boolean Enabled {get;set;}\r\nGivenName          Property              System.String GivenName {get;set;}\r\nName               Property              System.String Name {get;}\r\nObjectClass        Property              System.String ObjectClass {get;set;}\r\nObjectGUID         Property              System.Nullable`1[[System.Guid, mscorlib, Version=2.0.0.0, Culture=neutral,...\r\nPSShowComputerName Property              Microsoft.ActiveDirectory.Management.ADPropertyValueCollection PSShowComput...\r\nSamAccountName     Property              System.String SamAccountName {get;set;}\r\nSID                Property              System.Security.Principal.SecurityIdentifier SID {get;set;}\r\nSurname            Property              System.String Surname {get;set;}\r\nUserPrincipalName  Property              System.String UserPrincipalName {get;set;}\r\nWriteErrorStream   Property              Microsoft.ActiveDirectory.Management.ADPropertyValueCollection WriteErrorSt...\r\n<\/pre>\n<p>Nope nothing there. So let&#8217;s look through the help. Nothing in basic help. So onto the -Detailed help.<\/p>\n<p>I get to the -Properties parameter<\/p>\n<p><code>   -Properties <string[]><br \/>\n       Specifies the properties of the output object to retrieve from the server. Use this parameter to retrieve properties that are not included in the default set.<br \/>\n<\/code><\/p>\n<p>I guess that answers part of my question. So what are all the properties that I can look at? Reading a little further on<\/p>\n<p><code>To retrieve and display the list of all the properties for an ADGroup object, use the following command:<br \/>\n  Get-ADGroup -Identity Administrators -Properties *| Get-Member<\/code><\/p>\n<p>So I alter my query like so:<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\nPS &gt;$thisuser = Get-ADUser -Filter 'Name -like &quot;LogonID&quot;' -Properties *\r\nPS &gt;$thisuser\r\n\r\nAccountExpirationDate              :\r\naccountExpires                     : 9223372036854775807\r\nAccountLockoutTime                 :\r\nAccountNotDelegated                : False\r\nAllowReversiblePasswordEncryption  : False\r\nBadLogonCount                      : 0\r\nbadPwdCount                        : 0\r\nCannotChangePassword               : False\r\n...\r\n<\/pre>\n<p>I will save space and not put the whole lot here. You get the picture.<\/p>\n<p>So as a result I can now see an item called MemberOf which contains the information I am after. Now I can change my query to be the following.<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\nPS &gt; Get-ADUser -Filter 'Name -like &quot;LogonID&quot;' -Properties MemberOf\r\n\r\nDistinguishedName  : CN=LogonID,OU=Users,DC=Home,DC=local\r\nEnabled            : True\r\nGivenName          : John\r\nMemberOf           : {CN=vCloud-SANDPIT-User,OU=Groups,DC=Home,DC=local, CN=vCloud-Infra-PowerUser,OU=Groups,DC=Home,DC=local, CN=vCOps-Admins,OU=Groups,DC=Home,DC=local...}\r\nName               : LogonID\r\nObjectClass        : user\r\nObjectGUID         : 9383f28b-e4fc-4a8e-81e4-73094d4bba63\r\nPSShowComputerName : {}\r\nSamAccountName     : LogonID\r\nSID                : S-1-5-21-9871330858-2016497126-1624845914-51132\r\nSurname            : Doe\r\nUserPrincipalName  : LogonID@home.local\r\nWriteErrorStream   : {}\r\nPropertyNames      : {DistinguishedName, Enabled, GivenName, Name...}\r\nPropertyCount      : 12\r\n<\/pre>\n<p>If you are curious about what Filtering you can do with ActiveDirectory run the following at a Powershell promopt:<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\nhelp about_ActiveDirectory_Filter\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Why is it that I cannot seem to see the groups a user is a member of when I use the Get-ADUser cmdlet? Surely this a very common question. Let <a href=\"https:\/\/threemillion.net\/blog\/?p=499\" class=\"more-link\">[&hellip;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"Layout":"","footnotes":""},"categories":[8],"tags":[57,56,58],"class_list":["entry","author-admin","post-499","post","type-post","status-publish","format-standard","category-powershell","tag-active-directory","tag-filter","tag-get-aduser"],"_links":{"self":[{"href":"https:\/\/threemillion.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/499","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/threemillion.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/threemillion.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/threemillion.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/threemillion.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=499"}],"version-history":[{"count":4,"href":"https:\/\/threemillion.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/499\/revisions"}],"predecessor-version":[{"id":503,"href":"https:\/\/threemillion.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/499\/revisions\/503"}],"wp:attachment":[{"href":"https:\/\/threemillion.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/threemillion.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=499"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/threemillion.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}