{"id":1656,"date":"2022-01-24T09:07:56","date_gmt":"2022-01-24T07:07:56","guid":{"rendered":"https:\/\/helia.ee\/koolitus\/?page_id=1656"},"modified":"2022-01-24T09:07:56","modified_gmt":"2022-01-24T07:07:56","slug":"microsoft-windows-2019-how-to-export-laps-passwords-from-active-directory-with-powershell","status":"publish","type":"page","link":"https:\/\/helia.ee\/koolitus\/?page_id=1656","title":{"rendered":"Microsoft Windows 2019 &#8211; How To Export LAPS Passwords from Active Directory with Powershell"},"content":{"rendered":"<p><strong>In this guide, I\u2019m going to show you how to export the LAPS passwords from Active Directory using a 3-line Powershell script.<\/strong><\/p>\n<p>This script automatically exports all LAPS passwords from Active Directory to a CSV file with the date appended to the file name. I then schedule this to run monthly using Task Scheduler.<\/p>\n<hr class=\"wp-block-separator\" \/>\n<h2><span id=\"ezoic-pub-ad-placeholder-116\" class=\"ezoic-adpicker-ad\"><\/span>Why export LAPS passwords?<\/h2>\n<p><span id=\"ezoic-pub-ad-placeholder-125\" class=\"ezoic-adpicker-ad\"><\/span>I\u2019m assuming if you ended up on this post, you know that LAPS is Microsoft\u2019s way of automating password changes for local administrator accounts. I\u2019ve been using LAPS for years, and it just works. Here\u2019s a decent\u00a0<a href=\"https:\/\/www.veeam.com\/blog\/microsoft-laps-deployment-configuration-troubleshoot-guide.html\" data-lasso-id=\"69813\">LAPS install guide<\/a>\u00a0if you haven\u2019t set up LAPS yet.<\/p>\n<p><strong><em>So, why export LAPS passwords to begin with?<\/em><\/strong><\/p>\n<p>There are several reasons why you should to export them. Over the years, there have been 3 scenarios in which I wish I would\u2019ve have an export of LAPS passwords:<\/p>\n<ol>\n<li><strong><a href=\"https:\/\/smarthomepursuits.com\/create-pdq-deploy-report-to-show-local-admins\/\" data-lasso-id=\"69814\">When moving Administrator users to Standard users<\/a>.<\/strong>\u00a0The user takes the laptop offsite, and the LAPS password has expired. I wish I would\u2019ve had a way to look up what the previous password was when troubleshooting random issues or installing new software.<\/li>\n<li><strong>DNS not resolving over the VPN.<\/strong>\u00a0Occasionally, certain users won\u2019t be able to get DNS to resolve over our\u00a0<a href=\"https:\/\/smarthomepursuits.com\/how-to-integrate-duo-2fa-into-openvpn\/\" data-lasso-id=\"69815\">OpenVPN Duo<\/a>\u00a0connection. This means that even though LAPS changes the password in Active Directory, their computer still has the old passwords. This means any admin-related tasks I need to do won\u2019t work until they come back onsite.<\/li>\n<li><strong>Domain controller unavailable.<\/strong>\u00a0Although rare, there have been a few occasions where our domain was temporarily unavailable. While I could log in with Windows cached credentials on most machines, there were several servers I hadn\u2019t logged into in a while and could not. Without being able to RDP to a domain controller, or launch the LAPS Fat Client UI, I had no way of accessing those machines.<\/li>\n<\/ol>\n<p class=\"has-white-color has-pale-pink-background-color has-text-color has-background\">If have any concerns about running into any of those scenarios above, then you might consider exporting LAPS passwords in case of emergency as well.<\/p>\n<hr class=\"wp-block-separator\" \/>\n<h2><span id=\"ezoic-pub-ad-placeholder-128\" class=\"ezoic-adpicker-ad\"><\/span>Isn\u2019t exporting passwords a security concern?<\/h2>\n<p>Technically, yes. However, in my opinion, you have to weigh the risk vs potential reward. Sure, exporting passwords in plaintext and leaving them on your desktop isn\u2019t secure. But if you\u2019re exporting them monthly, storing them on your non-domain password vault, or into a file share locked down with tight ACL\u2019s, then the risk is mitigated much more.<\/p>\n<p>Also something to keep in mind, if you\u2019ve granted your daily driver user account to view LAPS passwords and has permission to use the ADUC widget, then you can view all LAPS passwords right from your work PC anyway, without logging into a Domain Controller.<\/p>\n<p><strong>Open Active Directory Users &amp; Computers &gt; Right click a computer object &gt; Properties &gt; Attribute Editor.\u00a0<\/strong>Scroll until you see the\u00a0<strong>ms-Mcs-AdmPwd<\/strong>. You\u2019ll see the LAPS password clear as day there.<\/p>\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-3387 ezlazyloaded\" src=\"https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-15.png?ezimgfmt=rs:585x469\/rscb16\/ng:webp\/ngcb16\" sizes=\"auto, (max-width: 585px) 100vw, 585px\" srcset=\"https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-15.png?ezimgfmt=ng:webp\/ngcb16 585w,https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-15-300x241.png?ezimgfmt=ng:webp\/ngcb16 300w\" alt=\"\" width=\"585\" height=\"469\" data-ezsrcset=\"https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-15.png?ezimgfmt=ng:webp\/ngcb16 585w,https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-15-300x241.png?ezimgfmt=ng:webp\/ngcb16 300w\" data-ezsrc=\"https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-15.png?ezimgfmt=rs:585x469\/rscb16\/ng:webp\/ngcb16\" \/><\/figure>\n<hr class=\"wp-block-separator\" \/>\n<h2><span id=\"ezoic-pub-ad-placeholder-126\" class=\"ezoic-adpicker-ad\"><\/span>Laps Export Powershell Script<\/h2>\n<p>This script assumes that LAPS has already been configured into your environment &amp; that your user account already has access to view LAPS passwords using the Fat Client UI or from Active Directory Users &amp; Computers.<\/p>\n<p>This script loads the Active Directory module, finds the LAPS password fields, and then saves them to a CSV with the date appended to the file name. The only thing you\u2019d need to change is the file path.<\/p>\n<p><strong>Just Open Powershell and paste this script:<\/strong><\/p>\n<p><code>$Computers = Get-ADComputer -Filter * -Properties ms-Mcs-AdmPwd, ms-Mcs-AdmPwdExpirationTime<br \/>\n$Computers | Sort-Object ms-Mcs-AdmPwdExpirationTime | Format-Table -AutoSize Name, DnsHostName, ms-Mcs-AdmPwd, ms-Mcs-AdmPwdExpirationTime<br \/>\n$computers | Export-Csv -path c:\\users\\danny\\desktop\\\"LAPS-$((Get-Date).ToString(\"MM-dd-yyyy\")).csv\" -NoTypeInformation<\/code><\/p>\n<p>Then, save it to the location of your choice. For this example, I\u2019m saving to\u00a0<strong>C:\\Scripts\\LAPSexport.ps1<\/strong>.<\/p>\n<p>Then, run the script to verify it works correctly. If it does, you should automate this procedure by creating a Scheduled Task.<\/p>\n<hr class=\"wp-block-separator\" \/>\n<h2><span id=\"ezoic-pub-ad-placeholder-114\" class=\"ezoic-adpicker-ad\"><\/span>LAPS Export Scheduled Task \/ PDQ Schedule<\/h2>\n<p>To schedule this to run on a schedule, open Task Scheduler &gt; Create Task. Give it a name and configure the correct operating system version and user to run as.<\/p>\n<ul>\n<li>Under\u00a0<strong>Triggers<\/strong>, select your frequency.<\/li>\n<li>Under\u00a0<strong>Actions,<\/strong>\u00a0choose Start A Program.\n<ul>\n<li><strong>Program Script:<\/strong>\u00a0C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe<\/li>\n<\/ul>\n<ul>\n<li><strong>Add Arguments:<\/strong>\u00a0path to file (C:\\users\\Scripts\\LAPSexport.ps1)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Then, just click OK and save. Right click and run the task to confirm that it\u2019s working correctly.<\/p>\n<p>If you have PDQ Deploy in your environment, you could also schedule this to run monthly there.<\/p>\n<ol>\n<li><strong>Create a new package.<\/strong>\u00a0Give it a name like\u00a0<em>LAPS Monthly Export<\/em>\u00a0and paste the script in and SAVE.<\/li>\n<li>Click the\u00a0<strong>Schedules tab<\/strong>, then\u00a0<strong>right click the empty space &gt; New Schedule<\/strong>. Set the schedule.<\/li>\n<li>Click the\u00a0<strong>Target tab,<\/strong>\u00a0choose a PC that has access to view LAPS passwords, like your own.<\/li>\n<\/ol>\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-3389 ezlazyloaded\" src=\"https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-16-1024x303.png?ezimgfmt=rs:742x219\/rscb16\/ng:webp\/ngcb16\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" srcset=\"https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-16-1024x303.png?ezimgfmt=ng:webp\/ngcb16 1024w,https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-16-300x89.png?ezimgfmt=ng:webp\/ngcb16 300w,https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-16-768x227.png?ezimgfmt=ng:webp\/ngcb16 768w,https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-16-1170x346.png?ezimgfmt=ng:webp\/ngcb16 1170w,https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-16-585x173.png?ezimgfmt=ng:webp\/ngcb16 585w,https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-16.png?ezimgfmt=ng:webp\/ngcb16 1414w\" alt=\"\" width=\"1024\" height=\"303\" data-ezsrcset=\"https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-16-1024x303.png?ezimgfmt=ng:webp\/ngcb16 1024w,https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-16-300x89.png?ezimgfmt=ng:webp\/ngcb16 300w,https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-16-768x227.png?ezimgfmt=ng:webp\/ngcb16 768w,https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-16-1170x346.png?ezimgfmt=ng:webp\/ngcb16 1170w,https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-16-585x173.png?ezimgfmt=ng:webp\/ngcb16 585w,https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-16.png?ezimgfmt=ng:webp\/ngcb16 1414w\" data-ezsrc=\"https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-16-1024x303.png?ezimgfmt=rs:742x219\/rscb16\/ng:webp\/ngcb16\" \/><\/figure>\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-3390 ezlazyloaded\" src=\"https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-17.png?ezimgfmt=rs:465x294\/rscb16\/ng:webp\/ngcb16\" sizes=\"auto, (max-width: 465px) 100vw, 465px\" srcset=\"https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-17.png?ezimgfmt=ng:webp\/ngcb16 465w,https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-17-300x190.png?ezimgfmt=ng:webp\/ngcb16 300w\" alt=\"\" width=\"465\" height=\"294\" data-ezsrcset=\"https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-17.png?ezimgfmt=ng:webp\/ngcb16 465w,https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-17-300x190.png?ezimgfmt=ng:webp\/ngcb16 300w\" data-ezsrc=\"https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-17.png?ezimgfmt=rs:465x294\/rscb16\/ng:webp\/ngcb16\" \/><\/figure>\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-3391 ezlazyloaded\" src=\"https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-18.png?ezimgfmt=rs:663x604\/rscb16\/ng:webp\/ngcb16\" sizes=\"auto, (max-width: 663px) 100vw, 663px\" srcset=\"https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-18.png?ezimgfmt=ng:webp\/ngcb16 663w,https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-18-300x273.png?ezimgfmt=ng:webp\/ngcb16 300w,https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-18-585x533.png?ezimgfmt=ng:webp\/ngcb16 585w\" alt=\"\" width=\"663\" height=\"604\" data-ezsrcset=\"https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-18.png?ezimgfmt=ng:webp\/ngcb16 663w,https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-18-300x273.png?ezimgfmt=ng:webp\/ngcb16 300w,https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-18-585x533.png?ezimgfmt=ng:webp\/ngcb16 585w\" data-ezsrc=\"https:\/\/smarthomepursuits.com\/wp-content\/uploads\/2021\/02\/image-18.png?ezimgfmt=rs:663x604\/rscb16\/ng:webp\/ngcb16\" \/><\/figure>\n<h2>Wrapping Up<\/h2>\n<p>Hopefully this simple script helps you export your LAPS passwords quickly and easily. Let me know if you run into any issues or have any modifications that you\u2019ve made to the script.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, I\u2019m going to show you how to export the LAPS passwords from Active Directory using a 3-line Powershell script. This script automatically exports all LAPS passwords from Active Directory to a CSV file with the date appended to the file name. I then schedule this to run monthly using Task Scheduler. Why [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1304,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"class_list":["post-1656","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/helia.ee\/koolitus\/index.php?rest_route=\/wp\/v2\/pages\/1656","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/helia.ee\/koolitus\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/helia.ee\/koolitus\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/helia.ee\/koolitus\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/helia.ee\/koolitus\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1656"}],"version-history":[{"count":1,"href":"https:\/\/helia.ee\/koolitus\/index.php?rest_route=\/wp\/v2\/pages\/1656\/revisions"}],"predecessor-version":[{"id":1657,"href":"https:\/\/helia.ee\/koolitus\/index.php?rest_route=\/wp\/v2\/pages\/1656\/revisions\/1657"}],"up":[{"embeddable":true,"href":"https:\/\/helia.ee\/koolitus\/index.php?rest_route=\/wp\/v2\/pages\/1304"}],"wp:attachment":[{"href":"https:\/\/helia.ee\/koolitus\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1656"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}