{"id":4297,"date":"2017-10-16T17:00:51","date_gmt":"2017-10-16T15:00:51","guid":{"rendered":"https:\/\/www.razumny.no\/?p=4297"},"modified":"2017-09-29T10:03:26","modified_gmt":"2017-09-29T08:03:26","slug":"powershell-exporting-active-directory-contacts","status":"publish","type":"post","link":"https:\/\/www.razumny.no\/?p=4297","title":{"rendered":"Powershell: Exporting Active Directory Contacts"},"content":{"rendered":"<p>Some time ago, I needed to have a list of all Contacts registered in Active Directory. Knowing that there are a lot of them (numbering at least eighty), getting the data manually was not a viable alternative, particularly knowing that the same objective can be achieved through Powershell. I eventually came up with a solution. To make following it logically easier, I&#8217;m going to include commentary on each step:<\/p>\n<ul>\n<li>First, we need to retrieve Active Directory objects. This is done with the cmdlet\u00a0<code>Get-ADObject<\/code><\/li>\n<li>Next, we need to filter those results, based on the type of object. This is done with\u00a0<code>-LDAPFilter \"objectClass=contact\"<\/code><\/li>\n<li>Running this straight will not include email addresses. In order to get those, we add\u00a0<code>-Properties \"mail\"<\/code><\/li>\n<li>I wanted this exported as a file, which is done by the final part of the script: <code>| Export-CSV filename.csv<\/code><\/li>\n<\/ul>\n<p>All together, the final script looks like this:<\/p>\n<p><code>Get-ADObject -LDAPFilter \"objectClass=contact\" -Properties \"mail\" | Export-CSV filename.csv<\/code><\/p>\n<p>When testing it, I noted that each result was listed neatly with Distinguished Name, e-mail address, name, ObjectClass and ObjectGUID in separate rows. In order to get an export that was more readily legible, I replaced Export-CSV with <code>Out-File fillename.txt<\/code>, which dumped the result to a text file in much the same way as using <code>&gt;<\/code> would in the Windows command line. That script looks like this:<\/p>\n<p><code>Get-ADObject -LDAPFilter \"objectClass=contact\" -Properties \"mail\" | Out-File filename.txt<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Some time ago, I needed to have a list of all Contacts registered in Active Directory. Knowing that there are a lot of them (numbering at least eighty), getting the data manually was not a viable alternative, particularly knowing that the same objective can be achieved through Powershell. I eventually came up with a solution. [&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":[119,615],"tags":[760,1075,1076,969],"class_list":["post-4297","post","type-post","status-publish","format-standard","hentry","category-code-examples","category-how-to-2","tag-active-directory","tag-get-adobject","tag-ldapfilter","tag-powershell"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/p2ukSU-17j","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":5402,"url":"https:\/\/www.razumny.no\/?p=5402","url_meta":{"origin":4297,"position":0},"title":"PowerShell: Count enabled user accounts","author":"Aleksander Nordgarden-R\u00f8dner","date":"16\/03\/2020","format":false,"excerpt":"A few weeks ago, I showed you how to get a list of all enabled user accounts in PowerShell. Perhaps unsurprisingly, after having presented this to my customer, it transpired that what they really wanted, was to know how many enabled user accounts existed in Active Directory. Once more, my\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":4297,"position":1},"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":7210,"url":"https:\/\/www.razumny.no\/?p=7210","url_meta":{"origin":4297,"position":2},"title":"Installing ADUC from PowerShell","author":"Aleksander Nordgarden-R\u00f8dner","date":"19\/06\/2023","format":false,"excerpt":"With some frequency, I have users contacting me to have ADUC (Active Directory Users and Computers) installed on their computers. While you can simply install RSAT from Apps & Features, doing so would be overkill and a half. Much better, then, to simply install ADUC and be done with it.\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":2419,"url":"https:\/\/www.razumny.no\/?p=2419","url_meta":{"origin":4297,"position":3},"title":"Exporting a list of a given users group memberships from Active Directory","author":"Aleksander Nordgarden-R\u00f8dner","date":"05\/05\/2014","format":false,"excerpt":"A while back, I showed you how to export a list of all members of a group, as well as all computers, from Active Directory. On a related note, here's how to export all group memberships held by a single user: Log on to your Domain Controller Open a command\u2026","rel":"","context":"In &quot;code examples&quot;","block_context":{"text":"code examples","link":"https:\/\/www.razumny.no\/?cat=119"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":5400,"url":"https:\/\/www.razumny.no\/?p=5400","url_meta":{"origin":4297,"position":4},"title":"PowerShell: Find all enabled user accounts","author":"Aleksander Nordgarden-R\u00f8dner","date":"17\/02\/2020","format":false,"excerpt":"Some time ago, I was asked to provide a list of all enabled user accounts in Active Directory. My thoughts immediately went to PowerShell, assuming that there would be tools available to achieve that task. I knew that the Get-ADUser query, combined with a parameter, would likely be the ticket.\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":6996,"url":"https:\/\/www.razumny.no\/?p=6996","url_meta":{"origin":4297,"position":5},"title":"PowerShell: &#8220;Some or all identity references could not be translated&#8221;","author":"Aleksander Nordgarden-R\u00f8dner","date":"05\/12\/2022","format":false,"excerpt":"For a whole host of reasons we use scripts to create access controlled file shares, and to create the Active Directory groups that control access to them. Not only is it easier than doing it manually, it also ensures that the group is created in the correct place, that permissions\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/www.razumny.no\/?cat=820"},"img":{"alt_text":"Picture of text:\n\nRetry-Command: Some or all identity references could not be translated.\nAt C:\\Scripts\\Opprette-Styrtomr\u00e5de.ps1:113 char:1\n+ Retry-Command -ScriptBlock {\n+\n+ CategoryInfo\n+ FullyQualified Error Id: Microsoft.\n: NotSpecified: (:) [Write-Error], WriteError Exception\nPowerShell.Commands.WriteError Exception, Retry-Command","src":"https:\/\/i0.wp.com\/www.razumny.no\/wp-content\/uploads\/image-107.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.razumny.no\/wp-content\/uploads\/image-107.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.razumny.no\/wp-content\/uploads\/image-107.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.razumny.no\/index.php?rest_route=\/wp\/v2\/posts\/4297","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=4297"}],"version-history":[{"count":3,"href":"https:\/\/www.razumny.no\/index.php?rest_route=\/wp\/v2\/posts\/4297\/revisions"}],"predecessor-version":[{"id":4307,"href":"https:\/\/www.razumny.no\/index.php?rest_route=\/wp\/v2\/posts\/4297\/revisions\/4307"}],"wp:attachment":[{"href":"https:\/\/www.razumny.no\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.razumny.no\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4297"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.razumny.no\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}