{"id":5404,"date":"2020-02-24T17:00:00","date_gmt":"2020-02-24T16:00:00","guid":{"rendered":"https:\/\/www.razumny.no\/?p=5404"},"modified":"2020-02-17T11:40:44","modified_gmt":"2020-02-17T10:40:44","slug":"powershell-find-all-users-in-a-specific-ou","status":"publish","type":"post","link":"https:\/\/www.razumny.no\/?p=5404","title":{"rendered":"PowerShell: Find all users in a specific OU"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">One of my customers asked for an overview of the UPNs of all users in a specific OU. Having become fairly familiar with the Get-ADUser command, I decided to see if I couldn&#8217;t make it do this, too.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I knew that I would need to filter the results of the command on OU, and found that the <code>-filter<\/code> parameter, combined with <code>-SearchBase<\/code> would give me what I wanted. To this end, I ran the following command:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Get-ADUser -Filter * -SearchBase \u201cou=ouname,dc=company,dc=com\u201d<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That, however, did not give me the result I was looking for. For that, I needed to pipe the results through a second command to get the UPN, and then a third to select it and output it to a file. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Get-ADUser -Filter * -SearchBase \u201cou=ouname,dc=company,dc=com\u201d | Get-ADUser -property UserPrincipalName | select UserPrincipalName > results.txt<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of my customers asked for an overview of the UPNs of all users in a specific OU. Having become fairly familiar with the Get-ADUser command, I decided to see if I couldn&#8217;t make it do this, too. I knew that I would need to filter the results of the command on OU, and found [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[820],"tags":[1187,1220,1221],"class_list":["post-5404","post","type-post","status-publish","format-standard","hentry","category-powershell","tag-get-aduser","tag-upn","tag-userprincipalname"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/p2ukSU-1pa","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":5451,"url":"https:\/\/www.razumny.no\/?p=5451","url_meta":{"origin":5404,"position":0},"title":"PowerShell: Pipe output to CSV file","author":"Aleksander Nordgarden-R\u00f8dner","date":"11\/05\/2020","format":false,"excerpt":"Last week, I showed you how to get specific properties for all users in a given OU. Knowing that the output of that query quickly gets hard to navigate, wanting to remove the extraneous data that the customer didn't request, and assuming that they wanted to manipulate the data, I\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/www.razumny.no\/?cat=820"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":5450,"url":"https:\/\/www.razumny.no\/?p=5450","url_meta":{"origin":5404,"position":1},"title":"PowerShell: Getting properties for all user objects in a given OU","author":"Aleksander Nordgarden-R\u00f8dner","date":"04\/05\/2020","format":false,"excerpt":"Two weeks ago, I showed you how I got some specific properties for a specific user. Perhaps unsurprisingly, the next request from my customer was a similar dump from a specific OU. While the Identity parameter works well when you're dealing with a specific user, it doesn't help when you\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/www.razumny.no\/?cat=820"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":5265,"url":"https:\/\/www.razumny.no\/?p=5265","url_meta":{"origin":5404,"position":2},"title":"Building a script to find all members of a given group","author":"Aleksander Nordgarden-R\u00f8dner","date":"09\/09\/2019","format":false,"excerpt":"Some time ago, I was asked to provide a list of everyone with access to a specific system. After communicating with the client, it transpired that they were particularly interested in knowing who were the members of a set of Active Directory groups. While this can be done manually, I\u2026","rel":"","context":"In &quot;How To&quot;","block_context":{"text":"How To","link":"https:\/\/www.razumny.no\/?cat=615"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":7070,"url":"https:\/\/www.razumny.no\/?p=7070","url_meta":{"origin":5404,"position":3},"title":"PowerShell: Find User based on partial name","author":"Aleksander Nordgarden-R\u00f8dner","date":"06\/02\/2023","format":false,"excerpt":"Some time ago, I needed to look up the account names of a handful of users in Active Directory. The information I had beforehand was their names. I did not have ADUC available to me, but I did have PowerShell. This is an excellent use case for the Get-ADUser cmdlet\u2026","rel":"","context":"In &quot;How To&quot;","block_context":{"text":"How To","link":"https:\/\/www.razumny.no\/?cat=615"},"img":{"alt_text":"Get-ADUser : A positional parameter cannot be found that accepts argument 'Firstname Surname'.\nAt line:1 char:1\n+ Get-ADUser -Filter displayName \"Firstname Surname\"\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n    + CategoryInfo          : InvalidArgument: (:) [Get-ADUser], ParameterBindingException\n    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.GetADUser","src":"https:\/\/i0.wp.com\/www.razumny.no\/wp-content\/uploads\/image-114.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.razumny.no\/wp-content\/uploads\/image-114.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.razumny.no\/wp-content\/uploads\/image-114.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.razumny.no\/wp-content\/uploads\/image-114.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":5446,"url":"https:\/\/www.razumny.no\/?p=5446","url_meta":{"origin":5404,"position":4},"title":"Powershell: Retrieving all properties for a given user object","author":"Aleksander Nordgarden-R\u00f8dner","date":"20\/04\/2020","format":false,"excerpt":"I was asked to provide an overview of all available properties in an Active Directory user object for an upcoming project. As it turns out, that is very easily accomplished. Unsurprisingly, PowerShell has an applet for this. We use the Get-ADUser applet, with the parameters Identity to identify the user\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/www.razumny.no\/?cat=820"},"img":{"alt_text":"Output of get-aduser command, filtering on identity and specific proeprties","src":"https:\/\/i0.wp.com\/www.razumny.no\/wp-content\/uploads\/image-13.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.razumny.no\/wp-content\/uploads\/image-13.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.razumny.no\/wp-content\/uploads\/image-13.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.razumny.no\/wp-content\/uploads\/image-13.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":5626,"url":"https:\/\/www.razumny.no\/?p=5626","url_meta":{"origin":5404,"position":5},"title":"PowerShell: Find all groups containing a specific string","author":"Aleksander Nordgarden-R\u00f8dner","date":"07\/09\/2020","format":false,"excerpt":"Sometimes, you need a list of all groups whose name contain a specific string, whether that is in the beginning, middle, or end of the group name. As we've seen previously, looking up groups in PowerShell is done with the Get-ADGroup command. Adding the -filter parameter allows us to find\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/www.razumny.no\/?cat=820"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.razumny.no\/index.php?rest_route=\/wp\/v2\/posts\/5404","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.razumny.no\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.razumny.no\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.razumny.no\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.razumny.no\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5404"}],"version-history":[{"count":2,"href":"https:\/\/www.razumny.no\/index.php?rest_route=\/wp\/v2\/posts\/5404\/revisions"}],"predecessor-version":[{"id":5410,"href":"https:\/\/www.razumny.no\/index.php?rest_route=\/wp\/v2\/posts\/5404\/revisions\/5410"}],"wp:attachment":[{"href":"https:\/\/www.razumny.no\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5404"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.razumny.no\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5404"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.razumny.no\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5404"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}