{"id":956,"date":"2014-07-24T00:01:00","date_gmt":"2014-07-24T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/07\/24\/transforming-the-active-directory-cmdlets-part-4\/"},"modified":"2022-06-13T14:21:45","modified_gmt":"2022-06-13T21:21:45","slug":"transforming-the-active-directory-cmdlets-part-4","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/transforming-the-active-directory-cmdlets-part-4\/","title":{"rendered":"Transforming the Active Directory Cmdlets: Part 4"},"content":{"rendered":"<p><b style=\"font-size:12px\">Summary<\/b><span style=\"font-size:12px\">: Learn how to translate between ADSI, Quest, and Windows PowerShell cmdlets to read additional user properties.<\/span><\/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\" \/>\u00a0Hey, Scripting Guy!<\/p>\n<p>I&#8217;m trying figure something out. I can get some properties with the Quest cmdlets without even asking, but when I go to use the Windows PowerShell cmdlets, they aren&#8217;t there. How can I get these properties from the system?<\/p>\n<p>\u2014RM<\/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\" \/>\u00a0Hello RM,<\/p>\n<p>Honorary Scripting Guy, Sean Kearney, here. Today you can peek in as I guide my old buddy, Kevin, through converting some of his newer Windows PowerShell goodies for Active Directory to some older things.<\/p>\n<p><strong>Note<\/strong> This is the fourth post in a series. For more, see:<\/p>\n<ul>\n<li><a href=\"https:\/\/devblogs.microsoft.com\/scripting\/transforming-the-active-directory-cmdlets-part-1\/\" target=\"_blank\" rel=\"noopener\">Transforming to<b> <\/b>Active Directory Cmdlets: Part 1<\/a><\/li>\n<li><a href=\"https:\/\/devblogs.microsoft.com\/scripting\/transforming-the-active-directory-cmdlets-part-2\/\" target=\"_blank\" rel=\"noopener\">Transforming to<b> <\/b>Active Directory Cmdlets: Part 2<\/a><\/li>\n<li><a href=\"https:\/\/devblogs.microsoft.com\/scripting\/transforming-the-active-directory-cmdlets-part-3\/\" target=\"_blank\" rel=\"noopener\">Transforming to<b> <\/b>Active Directory Cmdlets: Part 3<\/a><\/li>\n<\/ul>\n<p>Kevin is being asked to audit his company&#8217;s Active Directory to ensure key properties are populated in all of the user objects. A new application is being brought online to introduce a standard signature in the emails for all staff.<\/p>\n<p>&#8220;The problem I&#8217;ve noted,&#8221; as Kevin states while targeting his head for the shiny spot on the desk, &#8220;is that some of the staff are missing the email address and the standard website in their signatures. Although this is fine for a generic address, it&#8217;s not so good for managers.&#8221;<\/p>\n<p>I smiled, &#8220;So just run a <strong>Get-QADUser<\/strong> on them and&#8230;&#8221;<\/p>\n<p>&#8220;I found that the <strong>Get-QADUser<\/strong> cmdlet will work fine, but against our 150,000 user Active Directory, it was far too slow. So to test it out, this worked:<\/p>\n<p style=\"margin-left:30px\">\n  $UserInfo=GET-Qaduser Valentine-Michael.Sm\n<\/p>\n<p style=\"margin-left:30px\">\n  $WebSite=$UserInfo.Webpage\n<\/p>\n<p style=\"margin-left:30px\">\n  $Email=$Userinfo.Email\n<\/p>\n<p>&#8220;I found that I can pull the properties and write a script around that, but it&#8217;s very slow\u2014mostly because it pulls a lot of extra information that I don&#8217;t need. But when I run the same query with the Microsoft version, the date wasn&#8217;t there. I checked by piping it through <strong>Get-Member<\/strong>:<\/p>\n<p style=\"margin-left:30px\">\n  GET-ADUser Valentine-Michael.Sm | GET-Member\n<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/prod.evol.blogs.technet.com\/CommunityServer.Blogs.Components.WeblogFiles\/00\/00\/00\/76\/18\/0312.1.PNG\"><img decoding=\"async\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/prod.evol.blogs.technet.com\/CommunityServer.Blogs.Components.WeblogFiles\/00\/00\/00\/76\/18\/0312.1.PNG\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>&#8220;I found that this worked, but it gave me <strong>everything<\/strong>, which was again way too slow when working with tens of thousands of users:&#8221;<\/p>\n<p style=\"margin-left:30px\">\n  GET-ADUser Valentine-Michael.Sm \u2013properties *\n<\/p>\n<p>Smiling like a Cheshire Cat, I looked at Kevin, &#8220;Too easy, my friend. Let&#8217;s find the properties that match what you&#8217;re looking for and specify only them. We can do this with <strong>Get-Member<\/strong>, and a little &#8216;wildcarding&#8217;.&#8221;<\/p>\n<p style=\"margin-left:30px\">\n  GET-ADUser Valentine-Michael.Sm \u2013properties * | GET-Member \u2013name *email*\n<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/prod.evol.blogs.technet.com\/CommunityServer.Blogs.Components.WeblogFiles\/00\/00\/00\/76\/18\/6327.2.PNG\"><img decoding=\"async\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/prod.evol.blogs.technet.com\/CommunityServer.Blogs.Components.WeblogFiles\/00\/00\/00\/76\/18\/6327.2.PNG\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>But a few minutes later, he came back. &#8220;OK, it worked. But I still can&#8217;t find the website. I tried both of the following commands&#8230;and nothing.&#8221;<\/p>\n<p style=\"margin-left:30px\">\n  GET-ADUser Valentine-Michael.Sm \u2013properties * | GET-Member \u2013name *web*\n<\/p>\n<p style=\"margin-left:30px\">\n  GET-ADUser Valentine-Michael.Sm \u2013properties * | GET-Member \u2013name *www*\n<\/p>\n<p>So I showed Kevin a trick I learned a long time ago. Populate the value with something unique via Active Directory Users and Computers. Then pull all properties and look for that unique value.<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/prod.evol.blogs.technet.com\/CommunityServer.Blogs.Components.WeblogFiles\/00\/00\/00\/76\/18\/6378.3.PNG\"><img decoding=\"async\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/prod.evol.blogs.technet.com\/CommunityServer.Blogs.Components.WeblogFiles\/00\/00\/00\/76\/18\/6378.3.PNG\" border=\"0\" alt=\" \" \/><\/a><\/p>\n<p style=\"margin-left:30px\">\n  GET-Aduser Valentine-Michael.Sm \u2013properties *\n<\/p>\n<p>In moments, we visually spotted the name as being &#8220;Homepage.&#8221;<\/p>\n<p>Kevin continued, &#8220;I remember from Quest that if I want to access multiple properties, I could do it like this:<\/p>\n<p style=\"margin-left:30px\">\n  GET-Qaduser Valentine-Michael.Sm \u2013IncludedProperties MaxStorage,OtherPhone\n<\/p>\n<p>&#8220;I&#8217;m guessing that if I type it as follows with the <strong>\u2013Properties<\/strong> parameter, I&#8217;ll get the additional ones I want. I would think they should have a similar format for a list of items.&#8221;<\/p>\n<p style=\"margin-left:30px\">\n  GET-ADUser Valentine-Michael.Sm \u2013properties OfficeEmail,Homepage\n<\/p>\n<p>He looked at the screen and found all the details appearing in front of him:<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/prod.evol.blogs.technet.com\/CommunityServer.Blogs.Components.WeblogFiles\/00\/00\/00\/76\/18\/1351.4.PNG\"><img decoding=\"async\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/prod.evol.blogs.technet.com\/CommunityServer.Blogs.Components.WeblogFiles\/00\/00\/00\/76\/18\/1351.4.PNG\" border=\"0\" alt=\" \" \/><\/a><\/p>\n<p>Kevin mused for a moment, &#8220;I&#8217;ll bet these are the same names used by the <strong>[ADSI]<\/strong> accelerator because they&#8217;re using the actual names I would see in the ADSI Editor too. Just for fun, let me try something.&#8221;<\/p>\n<p>Kevin quickly typed the same query by using the <strong>[ADSI]<\/strong> accelerator:<\/p>\n<p style=\"margin-left:30px\">\n  $Name=&#8217;CN=Valentine-Michael Smith&#8217;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\n<\/p>\n<p style=\"margin-left:30px\">\n  $Parent=&#8217;OU=Grok,DC=Contoso,DC=Local&#8217;\n<\/p>\n<p style=\"margin-left:30px\">\n  $Class=&#8221;user&#8221;\n<\/p>\n<p style=\"margin-left:30px\">\n  $Connection=[ADSI]&#8221;LDAP:\/\/$Parent&#8221;\n<\/p>\n<p style=\"margin-left:30px\">\n  $GetUser=$Connection.invokeget($Class, $Name)\n<\/p>\n<p style=\"margin-left:30px\">\n  $WebSite=$GetUser.InvokeGet(&#8220;Homepage&#8221;)\n<\/p>\n<p style=\"margin-left:30px\">\n  $Email=$GetUser.InvokeGet(&#8220;EmailAddress&#8221;)\n<\/p>\n<p>&#8220;AhHa!&#8221; he jumped on top of the desk after checking the values, &#8220;It works!&#8221;<\/p>\n<p>Of course, after his great leap onto the desk, quite a few doors opened to see what happened and why a senior systems analyst would be dancing on his cubicle.<\/p>\n<p>Pop in to tomorrow as we wrap up converting between the Active Directory methods in Windows PowerShell. And maybe settle Kevin down a bit. \ud83d\ude09<\/p>\n<p>I invite you to follow The Scripting Guys on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\" rel=\"noopener\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\" rel=\"noopener\">Facebook<\/a>. If you have any questions, send an email to The Scripting Guys at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\" rel=\"noopener\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\" rel=\"noopener\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then remember eat your cmdlets each and every day with a dash of creativity.<\/p>\n<p>**Sean Kearney, **Windows PowerShell MVP and Honorary Scripting Guy<span style=\"font-size:12px\">\u00a0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Learn how to translate between ADSI, Quest, and Windows PowerShell cmdlets to read additional user properties. \u00a0Hey, Scripting Guy! I&#8217;m trying figure something out. I can get some properties with the Quest cmdlets without even asking, but when I go to use the Windows PowerShell cmdlets, they aren&#8217;t there. How can I get these [&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,56,3,154,45],"class_list":["post-956","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-active-directory","tag-guest-blogger","tag-scripting-guy","tag-sean-kearney","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Learn how to translate between ADSI, Quest, and Windows PowerShell cmdlets to read additional user properties. \u00a0Hey, Scripting Guy! I&#8217;m trying figure something out. I can get some properties with the Quest cmdlets without even asking, but when I go to use the Windows PowerShell cmdlets, they aren&#8217;t there. How can I get these [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/956","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=956"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/956\/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=956"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=956"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=956"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}