{"id":3986,"date":"2013-03-22T00:01:00","date_gmt":"2013-03-22T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/03\/22\/explore-active-directory-users-with-powershell-out-gridview\/"},"modified":"2013-03-22T00:01:00","modified_gmt":"2013-03-22T00:01:00","slug":"explore-active-directory-users-with-powershell-out-gridview","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/explore-active-directory-users-with-powershell-out-gridview\/","title":{"rendered":"Explore Active Directory Users with PowerShell Out-GridView"},"content":{"rendered":"<p><strong>Summary<\/strong>: Microsoft Scripting Guy, Ed Wilson, talks about using the Windows PowerShell <strong>Out-Gridview<\/strong> cmdlet to examine user information in Active Directory.<\/p>\n<p>&nbsp;<\/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 would like a way to use Windows PowerShell to view user information from Active Directory. I would like to be able to explore the returned information and be able to see what is going on. In other words, I need kind of an Active Directory microscope. You don&rsquo;t happen to have one do you?<\/p>\n<p>&mdash;BJ<\/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 BJ,<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. This has been a really busy week, and it is now 30 days until the <a href=\"http:\/\/powershell.org\/summit\/\">Windows PowerShell Summit<\/a> in in Redmond, Washington. The <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/tags\/scripting+wife\/\">Scripting Wife<\/a> and I are looking forward to attending this event. In fact, we have been looking forward to it for months. Finally, it is coming together. In one way, it will be a bit strange. This is because we are staying at the same hotel as a couple of members from the Charlotte, North Carolina Windows PowerShell User Group, so I know we will be hanging out some. But of course, the big reason for attending the event is to spend time with some of the world&rsquo;s best Windows PowerShell scripters. It will be a total geek fest the entire time. I will be making three presentations, and so next week I need to spend a decent amount of time honing them.<\/p>\n<p style=\"padding-left: 30px\"><strong>Note&nbsp;<\/strong>&nbsp;&nbsp;This is the fifth blog in a series about using the Active Directory module.<\/p>\n<ul>\n<li>In <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>, I provided an overview about the AD: drive and the Active Directory module.<em> <\/em><\/li>\n<li>In <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>I talked about how to use the Windows PowerShell provider to find user information in Active Directory.<\/li>\n<li>In <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2013\/03\/20\/use-powershell-to-find-non-default-user-properties-in-ad.aspx\" target=\"_blank\">Use PowerShell to Find Non-Default User Properties in AD<\/a>, I talked about how to retrieve additional properties beyond the four basic ones.<\/li>\n<li>In <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2013\/03\/21\/use-the-powershell-ad-provider-to-modify-user-attributes.aspx\" target=\"_blank\">Use the PowerShell AD Provider to Modify User Attributes<\/a>, I discussed using standard Windows PowerShell commands to modify users in AD DS.<\/li>\n<\/ul>\n<h2><span style=\"font-size: 1.5em\">Using Out-GridView to explore Active Directory user info<\/span><span style=\"font-size: 12px\">&nbsp;<\/span><\/h2>\n<p>One of the cool things I like to do with Windows PowerShell is pipe user information that I need to peruse to the <strong>Out-GridView<\/strong> cmdlet. I find it a very convenient way to explore user information. The result of this exploration can be a further refinement of an AD DS query, or it can be the end game itself. The command is simplicity itself. In the command that follows, I am on the Charlotte OU portion of my AD: drive. I use the <strong>dir<\/strong><em> <\/em>alias (alias for <strong>Get-ChildItem<\/strong>), and I specify that I want all properties by using a wildcard character. I pipe the results to <strong>Out-Gridview<\/strong>. That is it!&nbsp;<\/p>\n<p style=\"padding-left: 30px\">PS AD:\\ou=charlotte,dc=iammred,dc=net&gt; dir -Properties * | Out-GridView<\/p>\n<h2>Sorting and filtering data with Out-GridView<span style=\"font-size: 12px\">&nbsp;<\/span><\/h2>\n<p>The initial display of information is not all that great. In fact, it seems a bit cluttered, and even jumbled. This is shown in the image that follows.&nbsp;<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3515.hsg-3-22-13-01.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3515.hsg-3-22-13-01.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>The strength of using <strong>Out-GridView<\/strong> comes by adding a criteria. This is shown here.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4101.hsg-3-22-13-02.png\"><img decoding=\"async\" title=\"Image of menu\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4101.hsg-3-22-13-02.png\" alt=\"Image of menu\" \/><\/a><\/p>\n<p>After I select the attributes that I am interested in working with, I click <strong>Add<\/strong>. Now, the <strong>GridView<\/strong> changes to permit modifying the operator and adding the criteria. This is shown here.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7268.hsg-3-22-13-03.png\"><img decoding=\"async\" title=\"Image of menu\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7268.hsg-3-22-13-03.png\" alt=\"Image of menu\" \/><\/a>&nbsp;<\/p>\n<h2>Storing results and further parsing<\/h2>\n<p>In Windows PowerShell&nbsp;3.0, <strong>Out-GridView<\/strong> picks up a <strong>PassThru<\/strong><em> <\/em>parameter. This means that the filtering conducted in the <strong>Out-GridView<\/strong> can feed back to the Windows PowerShell console. In the following example, I throw all the user objects (and their associated properties) from the Charlotte OU to the <strong>Out-GridView<\/strong>. I then filter the results and I store the results in a variable. Next I use Windows PowerShell to further work with the results. The command is shown here:<\/p>\n<p style=\"padding-left: 30px\">PS AD:\\ou=charlotte,dc=iammred,dc=net&gt; $user = dir -Properties * | Out-GridView &ndash;PassThru&nbsp;<\/p>\n<p>The Out-GridView that is created by the command is shown here.&nbsp;<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0027.hsg-3-22-13-04.png\"><img decoding=\"async\" title=\"Image of menu\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0027.hsg-3-22-13-04.png\" alt=\"Image of menu\" \/><\/a><\/p>\n<p style=\"padding-left: 30px\"><strong>Note<\/strong> &nbsp;&nbsp;If you do not highlight all the lines, only the one line that is highlighted by default returns. So in the previous image, the filter criterion returns three objects. But right now, only the first line is highlighted, so only that object would return. Therefore, all three lines need to be highlighted, and then when OK is pressed, all three objects return to the variable.<\/p>\n<p>After filtering the objects with more than 500 logons, I go back to the Windows PowerShell console, and investigate the <strong>$user<\/strong> variable that contains the returned objects.<\/p>\n<p style=\"padding-left: 30px\">PS AD:\\ou=charlotte,dc=iammred,dc=net&gt; $user = dir -Properties * | out-gridview -Pass&nbsp;<\/p>\n<p style=\"padding-left: 30px\">Thru&nbsp;<\/p>\n<p style=\"padding-left: 30px\">PS AD:\\ou=charlotte,dc=iammred,dc=net&gt; $user.Count&nbsp;<\/p>\n<p style=\"padding-left: 30px\">3&nbsp;<\/p>\n<p>I do not even need to use an intermediate variable because I can pipe the results to another cmdlet. The following command pipes the results from whatever is filtered in the <strong>Out-Gridview<\/strong> cmdlet to <strong>Group-Object<\/strong>, where the objects are grouped by the name property.<\/p>\n<p style=\"padding-left: 30px\">PS AD:\\ou=charlotte,dc=iammred,dc=net&gt; dir -Properties * | out-gridview -PassThru | group name &nbsp;<\/p>\n<p style=\"padding-left: 30px\">Count Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Group&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&#8212;&#8211; &#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8211;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; 1 ED-PC&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {CN=ED-PC,OU=Charlotte,DC=iammred,DC=net}<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; 1 ed wilson&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\">&nbsp;&nbsp;&nbsp; 1 EDLT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {CN=EDLT,OU=Charlotte,DC=iammred,DC=net}<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; 1 HYPERV2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {CN=HYPERV2,OU=Charlotte,DC=iammred,DC=net}<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; 1 Regular User&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{CN=Regular User,OU=Charlotte,DC=iammred,DC=net}<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; 1 Sample User&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {CN=Sample User,OU=Charlotte,DC=iammred,DC=net}<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; 1 SQL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {CN=SQL,OU=Charlotte,DC=iammred,DC=net<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; 1 Teresa Wilson&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {CN=Teresa Wilson,OU=Charlotte,DC=iammred,DC=net}<\/p>\n<p>BJ, that is all there is to using the Active Directory module provider with the <strong>Out-GridView<\/strong> cmdlet. Active Directory Week will continue tomorrow when I will talk about discovering attribute names by using Windows PowerShell.<\/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 the Windows PowerShell Out-Gridview cmdlet to examine user information in Active Directory. &nbsp; &nbsp;Hey, Scripting Guy! I would like a way to use Windows PowerShell to view user information from Active Directory. I would like to be able to explore the returned information and be able [&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,422,3,4,198,45],"class_list":["post-3986","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-active-directory","tag-out-gridview","tag-scripting-guy","tag-scripting-techniques","tag-users","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using the Windows PowerShell Out-Gridview cmdlet to examine user information in Active Directory. &nbsp; &nbsp;Hey, Scripting Guy! I would like a way to use Windows PowerShell to view user information from Active Directory. I would like to be able to explore the returned information and be able [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3986","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=3986"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3986\/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=3986"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=3986"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=3986"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}