{"id":3999,"date":"2013-03-20T00:01:00","date_gmt":"2013-03-20T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/03\/20\/use-powershell-to-find-non-default-user-properties-in-ad\/"},"modified":"2013-03-20T00:01:00","modified_gmt":"2013-03-20T00:01:00","slug":"use-powershell-to-find-non-default-user-properties-in-ad","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/use-powershell-to-find-non-default-user-properties-in-ad\/","title":{"rendered":"Use PowerShell to Find Non-Default User Properties in AD"},"content":{"rendered":"<p><strong>Summary<\/strong>: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell and the Active Directory module provider to find non-default AD DS user properties.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\" \/>&nbsp;Hey, Scripting Guy! I need to find information about users such as office location, and phone number that is not returned by the Active Directory module provider by default. How do I do this?<\/p>\n<p>&mdash;DP<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\" \/>&nbsp;Hello DP,<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. Today is what is officially called the calm after the storm. Massive thunderstorms ripped through Charlotte last night, knocking out power and phones. Hey, that is OK; but dude, I lost my Internet connection in the process. Major bummer. With battery backups, a generator, and what-not, I can handle bad weather&mdash;as long as it does not knock out my Internet connection. I do not have a backup ISP provider. Hey, where I live, I was lucky to get the one I have. Oh, well.<\/p>\n<p>Guess what? I was just told that Windows PowerShell MVP and <a href=\"http:\/\/blogs.technet.comhttps:\/\/devblogs.microsoft.com\/scripting\/honorary-scripting-guy-award-recipients-announced\/\" target=\"_blank\">honorary Scripting Guy<\/a>, <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/tags\/sean+kearney\/\" target=\"_blank\">Sean Kearney<\/a>, will be presenting at Microsoft TechEd in New Orleans and in Madrid. Way to go Sean! By the way, there are two more days until the <a href=\"http:\/\/northamerica.msteched.com\/?mtag=sg1\" target=\"_blank\">$300 discount expires<\/a>.<\/p>\n<p style=\"padding-left: 30px\"><strong>Note<\/strong>&nbsp;&nbsp;&nbsp;This is the third in a series of blog postings about using the Active Directory module provider. The first blog is an overview called <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2013\/03\/18\/playing-with-the-ad-drive-for-fun-and-profit.aspx\" target=\"_blank\">Playing with the AD: Drive for Fun and Profit<\/a>.<em> <\/em>The second blog is <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2013\/03\/19\/find-active-directory-user-information-with-the-windows-powershell-provider.aspx\" target=\"_blank\">Find Active Directory User Information with the PowerShell Provider<\/a><em>, <\/em>in which I talk about how to use the Windows PowerShell provider to find user information in Active Directory.<\/p>\n<h3><span style=\"font-size: 1.17em\">Quick review<\/span><\/h3>\n<p>To create the Charlotte: PSDrive (points to the Charlotte organizational unit or OU), I ran the following commands. (Obviously, you need to change the commands to point to an OU and a domain that exist on your system.)<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; ipmo activedirectory<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; New-PSDrive -Name charlotte -PSProvider activedirectory -Root &#8220;AD:\\ou=charlot<\/p>\n<p style=\"padding-left: 30px\">te,dc=iammred,dc=net&#8221;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Used (GB)&nbsp;&nbsp;&nbsp;&nbsp; Free (GB) Provider&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Root<\/p>\n<p style=\"padding-left: 30px\">&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212; &#8212;&#8212;&#8211;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;-<\/p>\n<p style=\"padding-left: 30px\">charlotte&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ActiveDire&#8230; \/\/RootDSE\/ou=charlotte,dc=ia&#8230;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; sl charlotte:<\/p>\n<p style=\"padding-left: 30px\">PS charlotte:\\&gt;<\/p>\n<h2>Getting properties of the user<\/h2>\n<p>I might think that to easily see all of the information associated with the Ed Wilson user, I can pipe the output to the <strong>Format-List<\/strong> (<strong>fl<\/strong> is an alias) cmdlet as shown here.<\/p>\n<p style=\"padding-left: 30px\">PS charlotte:\\&gt; dir | ? name -match &#8216;ed wilson&#8217; | fl *<\/p>\n<p>The command and the output associated with the command are shown in the image that follows.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5001.hsg-3-20-13-01.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5001.hsg-3-20-13-01.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>The problem with this approach is that only four properties of the user return. The four default properties are <strong>DistinguishedName<\/strong>, <strong>Name<\/strong>, <strong>ObjectClass<\/strong>, and <strong>ObjectGUID<\/strong>. However, a quick look in Active Directory Users and Computers reveals that there are many more attributes and values available. This is shown here.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3568.hsg-3-20-13-02.png\"><img decoding=\"async\" title=\"Image of menu\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3568.hsg-3-20-13-02.png\" alt=\"Image of menu\" \/><\/a><\/p>\n<h2>What about Get-ADUser?<\/h2>\n<p>Due to performance reasons, the <strong>Get-ADUser<\/strong> cmdlet does not return all properties of a user object. It returns the following properties:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-ADUser &#8216;cn=ed wilson,ou=charlotte,dc=iammred,dc=net&#8217; | select -expand propertynames<\/p>\n<p style=\"padding-left: 30px\">DistinguishedName<\/p>\n<p style=\"padding-left: 30px\">Enabled<\/p>\n<p style=\"padding-left: 30px\">GivenName<\/p>\n<p style=\"padding-left: 30px\">Name<\/p>\n<p style=\"padding-left: 30px\">ObjectClass<\/p>\n<p style=\"padding-left: 30px\">ObjectGUID<\/p>\n<p style=\"padding-left: 30px\">SamAccountName<\/p>\n<p style=\"padding-left: 30px\">SID<\/p>\n<p style=\"padding-left: 30px\">Surname<\/p>\n<p style=\"padding-left: 30px\">UserPrincipalName<\/p>\n<p>Therefore, if I want to access additional attributes and their associated values, I need to specifically request the attributes I desire. Unfortunately, the attribute names bear little relationship to the names that appear in Active Directory Users and Computers. The best way to find the required attributes is to use ADSI Edit. In modern versions of ADSI Edit, there is a view that shows only attributes that contain values. <br \/> Consequently, it is fairly easy to match the actual name of the Active Directory attribute and the name that appears in Active Directory Users and Computers.<\/p>\n<p style=\"padding-left: 30px\"><strong>Note&nbsp;<\/strong>&nbsp;&nbsp;In my <a href=\"http:\/\/www.amazon.com\/Windows-PowerShell-3-0-Step\/dp\/0735663394\/ref=sr_1_2?s=books&amp;ie=UTF8&amp;qid=1363713348&amp;sr=1-2&amp;keywords=powershell+3.0\" target=\"_blank\">Windows PowerShell 3.0 Step by Step<\/a> book, I have a chapter that includes screenshots that map the Active Directory Users and Computers interface to the actual AD Attribute names.<\/p>\n<p>The ADSI Edit property sheet for the Ed Wilson user object is shown here.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2133.hsg-3-20-13-03.png\"><img decoding=\"async\" title=\"Image of menu\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2133.hsg-3-20-13-03.png\" alt=\"Image of menu\" \/><\/a><\/p>\n<h2>Use Get-ItemProperty to get other attributes<\/h2>\n<p>So what is the trick to obtaining additional attributes from the user object beyond the four default properties returned by <strong>Get-Item<\/strong>? One approach is to use the <strong>Get-ItemProperty<\/strong> cmdlet. This technique is shown here where I retrieve the city (lower case L) attribute for the user.<\/p>\n<p style=\"padding-left: 30px\">PS charlotte:\\&gt; Get-ItemProperty -Path &#8216;.\\CN=ed wilson&#8217; -Name l<\/p>\n<p style=\"padding-left: 30px\">l&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Charlotte<\/p>\n<p style=\"padding-left: 30px\">PSPath&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Microsoft.ActiveDirectory.Management\\ActiveDirectory::\/\/RootDSE\/CN=ed<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;wilson,ou=Charlotte,DC=Iammred,DC=net<\/p>\n<p style=\"padding-left: 30px\">PSParentPath : Microsoft.ActiveDirectory.Management\\ActiveDirectory::\/\/RootDSE\/ou=Ch<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; arlotte,DC=Iammred,DC=net<\/p>\n<p style=\"padding-left: 30px\">PSChildName&nbsp; : CN=ed wilson<\/p>\n<p style=\"padding-left: 30px\">PSDrive&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : charlotte<\/p>\n<p style=\"padding-left: 30px\">PSProvider&nbsp;&nbsp; : Microsoft.ActiveDirectory.Management\\ActiveDirectory<\/p>\n<h2><span style=\"font-size: 1.5em\">Use Get-Item to get other attributes<\/span><\/h2>\n<p>I do not have to use the <strong>Get-ItemProperty<\/strong> cmdlet to retrieve other attributes from a user object. I can use the <strong>Get-Item<\/strong> cmdlet and type in an array of attributes in the <strong>Properties<\/strong><em> <\/em>parameter. This technique is shown here where I add in the city (<strong>l<\/strong>) and the phone number (<strong>telephoneNumber<\/strong>) to the command.<\/p>\n<p style=\"padding-left: 30px\">PS charlotte:\\&gt; get-item -Path &#8220;cn=ed wilson&#8221; -Properties l, telephonenumber<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">PSPath&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Microsoft.ActiveDirectory.Management\\ActiveDirectory::\/\/RootDSE<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/cn=ed wilson,ou=charlotte,dc=iammred,dc=net<\/p>\n<p style=\"padding-left: 30px\">PSParentPath&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Microsoft.ActiveDirectory.Management\\ActiveDirectory::\/\/RootDSE<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/ou=charlotte,dc=iammred,dc=net<\/p>\n<p style=\"padding-left: 30px\">PSChildName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : cn=ed wilson<\/p>\n<p style=\"padding-left: 30px\">PSDrive&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : charlotte<\/p>\n<p style=\"padding-left: 30px\">PSProvider&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Microsoft.ActiveDirectory.Management\\ActiveDirectory<\/p>\n<p style=\"padding-left: 30px\">PSIsContainer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : True<\/p>\n<p style=\"padding-left: 30px\">distinguishedName&nbsp; : cn=ed wilson,ou=charlotte,dc=iammred,dc=net<\/p>\n<p style=\"padding-left: 30px\">l&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Charlotte<\/p>\n<p style=\"padding-left: 30px\">name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;: ed wilson<\/p>\n<p style=\"padding-left: 30px\">objectClass&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : user<\/p>\n<p style=\"padding-left: 30px\">objectGUID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : bb10b5a2-58d7-4f8a-ab10-2ee84fc7cb58<\/p>\n<p style=\"padding-left: 30px\">telephoneNumber&nbsp;&nbsp;&nbsp; : 555-555-1212<\/p>\n<p style=\"padding-left: 30px\">PropertyNames&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : {distinguishedName, l, name, objectClass&#8230;}<\/p>\n<p style=\"padding-left: 30px\">AddedProperties&nbsp;&nbsp;&nbsp; : {}<\/p>\n<p style=\"padding-left: 30px\">RemovedProperties&nbsp; : {}<\/p>\n<p style=\"padding-left: 30px\">ModifiedProperties : {}<\/p>\n<p style=\"padding-left: 30px\">PropertyCount&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 7<\/p>\n<h2>Use Get-Item and retrieve all of the attributes<\/h2>\n<p>I can also use a wildcard character (<strong>*<\/strong>) to retrieve all of the attributes for my user object. The command is shown here.<\/p>\n<p style=\"padding-left: 30px\">PS charlotte:\\&gt; get-item -Path &#8220;cn=ed wilson&#8221; -Properties *<\/p>\n<p>The command and its associated output are shown in the following image.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1031.hsg-3-20-13-04.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1031.hsg-3-20-13-04.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>DP, that is all there is to using the Active Directory module provider to find information about users. Active Directory Week will continue tomorrow when I will talk about modifying user attributes.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><strong>Ed Wilson, Microsoft Scripting Guy<\/strong>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell and the Active Directory module provider to find non-default AD DS user properties. &nbsp;Hey, Scripting Guy! I need to find information about users such as office location, and phone number that is not returned by the Active Directory module provider by default. How do [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[7,414,3,4,303,45],"class_list":["post-3999","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-active-directory","tag-providers","tag-scripting-guy","tag-scripting-techniques","tag-searching","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell and the Active Directory module provider to find non-default AD DS user properties. &nbsp;Hey, Scripting Guy! I need to find information about users such as office location, and phone number that is not returned by the Active Directory module provider by default. How do [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3999","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=3999"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3999\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=3999"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=3999"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=3999"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}