{"id":17411,"date":"2010-08-16T00:01:00","date_gmt":"2010-08-16T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2010\/08\/16\/using-powershell-to-find-all-disabled-users-in-active-directory\/"},"modified":"2010-08-16T00:01:00","modified_gmt":"2010-08-16T00:01:00","slug":"using-powershell-to-find-all-disabled-users-in-active-directory","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/using-powershell-to-find-all-disabled-users-in-active-directory\/","title":{"rendered":"Using PowerShell to Find All Disabled Users in Active Directory"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p><b>Summary<\/b>: The Scripting Guys discuss three different approaches to finding disabled user accounts in Active Directory Domain Services by using Windows PowerShell.<\/p>\n<p>&nbsp;<\/p>\n<p><span class=\"Apple-style-span\" style=\"text-indent: 0px;border-collapse: separate;font: medium 'Times New Roman';letter-spacing: normal;color: #000000\"><span class=\"Apple-style-span\" style=\"font-family: Arial, Helvetica, sans-serif;font-size: 12px\"><img decoding=\"async\" height=\"34\" width=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" align=\"left\" alt=\"Hey, Scripting Guy! Question\" border=\"0\" title=\"Hey, Scripting Guy! Question\" style=\"border-width: 0px\" \/><\/span><\/span>Hey, Scripting Guy! I would like to use Windows PowerShell to search <a href=\"http:\/\/gallery.technet.microsoft.com\/ScriptCenter\/en-us\/site\/search?f%5B0%5D.Type=RootCategory&amp;f%5B0%5D.Value=activedirectory&amp;f%5B0%5D.Text=Active%20Directory\">Active Directory<\/a> Domain Services (AD DS) for user accounts that are disabled. I had <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2005\/05\/12\/how-can-i-get-a-list-of-all-the-disabled-user-accounts-in-active-directory.aspx\">a VBScript script I had obtained from the Scripting Guys a long time ago,<\/a> but it is confusing and I would like to find a different approach if possible. We are migrating our scripting environment from VBScript to Windows PowerShell, so I would like to replace this script if possible. <\/p>\n<p>&#8212; EJ<\/p>\n<p>&nbsp;<\/p>\n<p><span class=\"Apple-style-span\" style=\"text-indent: 0px;border-collapse: separate;font: medium 'Times New Roman';letter-spacing: normal;color: #000000\"><span class=\"Apple-style-span\" style=\"font-family: Arial, Helvetica, sans-serif;font-size: 12px\"><img decoding=\"async\" height=\"34\" width=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" align=\"left\" alt=\"Hey, Scripting Guy! Answer\" border=\"0\" title=\"Hey, Scripting Guy! Answer\" style=\"border-width: 0px\" \/><\/span><\/span>Hello EJ, <\/p>\n<p>Microsoft Scripting Guy Ed Wilson here I am having flashbacks of <a href=\"http:\/\/en.wikipedia.org\/wiki\/Currywurst\">currywurst<\/a>, cool breezes coming across the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Alster\">Alster<\/a>, long walks through green meadows, and long talks into the evening with awesome friends. I was writing the chapters on Active Directory of my <a href=\"http:\/\/www.microsoft.com\/learning\/en\/us\/Book.aspx?ID=9541&amp;locale=en-us\">Windows PowerShell Scripting Guide<\/a> book for Microsoft Press when I arrived in <a href=\"http:\/\/en.wikipedia.org\/wiki\/Hamburg\">Hamburg<\/a> on the <a href=\"http:\/\/en.wikipedia.org\/wiki\/InterCityExpress\">ICE Train<\/a> from <a href=\"http:\/\/en.wikipedia.org\/wiki\/Frankfurt\">Frankfurt<\/a>. I took the following photo on a walk around the lake. The breeze caused the fountain to spray mist creating a rainbow near the water. <\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0842.hsg081610011_015637CF.jpg\"><img decoding=\"async\" height=\"454\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8461.hsg081610011_thumb_3F031F8B.jpg\" alt=\"Photo Ed took in Hamburg\" border=\"0\" title=\"Photo Ed took in Hamburg\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" \/><\/a> <\/p>\n<p>The ICE trains all have power outlets in them, which meant I was able to work on my laptop the entire train ride. Using Virtual PC 2007, I fired up an Active Directory domain controller and a workstation in the same domain, and set about writing Active Directory Service Interfaces (ADSI) code to locate disabled user accounts. <\/p>\n<p>The script I wrote to find disabled user accounts in my domain uses the <b>Win32_UserAccount<\/b> <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa394582(VS.85).aspx\">WMI<\/a> class. It is a very easy class to use in Windows PowerShell, and it works well for small domains. The script listed here also appeared in the <a href=\"http:\/\/www.amazon.com\/Windows-Server-2008-Security-Resource\/dp\/0735625042\/ref=sr_1_3?s=books&amp;ie=UTF8&amp;qid=1281627104&amp;sr=1-3\">Windows Server 2008 Security Resource Kit<\/a> that was part of the <a href=\"http:\/\/www.amazon.com\/gp\/product\/0735623619?ie=UTF8&amp;tag=tn-script-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0735623619\">Windows Server 2008 Resource Kit<\/a> (I wrote all 150 Windows PowerShell scripts that appear in those volumes). <\/p>\n<p>For other articles about searching Active Directory using Windows PowerShell, see <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/tags\/active+directory\/windows+powershell\/searching+active+directory\/\">this collection of Hey, Scripting Guy! Blog posts<\/a>. <\/p>\n<blockquote>\n<p><strong>LocateDisabledUsers.ps1<\/strong><\/p>\n<p><span style=\"color: #000000\">param(<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #2b91af\">$domain<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #2b91af\">$env<\/span><span style=\"color: #000000\">:userdomain,<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">[switch]<\/span><span style=\"color: #2b91af\">$query<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">[switch]<\/span><span style=\"color: #2b91af\">$whatif<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">[switch]<\/span><span style=\"color: #2b91af\">$help<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">[switch]<\/span><span style=\"color: #2b91af\">$examples<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">[switch]<\/span><span style=\"color: #2b91af\">$min<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">[switch]<\/span><span style=\"color: #2b91af\">$full<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #000000\">end<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">param<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Begin<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Functions<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">function<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">funHelp()<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #2b91af\">$descriptionText<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">`<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">@<\/span><span style=\"color: #808080\">&#8221; <br \/>NAME: LocateDisabledUsers.ps1&nbsp; <br \/>DESCRIPTION: <br \/>Locates disabled users a local or remote domain by <br \/>supplying the netbios name of the domain.&nbsp; <br \/>The script can query multiple domains by accepting&nbsp; <br \/>more than one value for the -domain parameter. The&nbsp; <br \/>script also supports using -whatif to prototype the&nbsp; <br \/>command prior to execution <br \/>PARAMETERS:&nbsp; <br \/>-domain the domain or domains to query for locked&nbsp; <br \/>out users. Note: this is the netbios domain name. <br \/>Does not accept fully qualified domain name. For <br \/>example: nwtraders is correct, nwtraders.com is&nbsp; <br \/>not. <br \/>-query executes the query <br \/>-whatif prototypes the command. <br \/>-help prints help description and parameters file <br \/>-examples prints only help examples of syntax <br \/>-full prints complete help information <br \/>-min prints minimal help. Modifies -help <br \/>&#8220;<\/span><span style=\"color: #000000\">@<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #000000\">end<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">descriptionText<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #2b91af\">$examplesText<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">`<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">@<\/span><span style=\"color: #808080\">&#8221; <br \/>SYNTAX: <br \/>LocateDisabledUsers.ps1 <br \/>Displays an error missing parameter, and calls help <br \/>LocateDisabledUsers.ps1 -query <br \/>Queries disabled user accounts. The domain queried is <br \/>the local logged on users domain from the machine&nbsp; <br \/>that launched the script&nbsp; <br \/>LocateDisabledUsers.ps1 -domain nwtraders, contoso -query <br \/>Queries disabled user accounts in the nwtraders domain and <br \/>in the contoso domain. The script is executed locally&nbsp; <br \/>LocateDisabledUsers.ps1 -query -domain nwtraders -whatif <br \/>Displays what if: Perform operation locate disabled&nbsp; <br \/>users from the nwtraders domain.The query will execute&nbsp; <br \/>from the localhost computer <br \/>LocateDisabledUsers.ps1 -help <br \/>Prints the help topic for the script <br \/>LocateDisabledUsers.ps1 -help -full <br \/>Prints full help topic for the script <br \/>LocateDisabledUsers.ps1 -help -examples <br \/>Prints only the examples for the script <br \/>LocateDisabledUsers.ps1 -examples <br \/>Prints only the examples for the script <br \/>&#8220;<\/span><span style=\"color: #000000\">@<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #000000\">end<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">examplesText<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #2b91af\">$remarks<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">`<\/span><span style=\"color: #808080\"> <br \/>&#8221; <br \/>REMARKS <br \/>For more information, type: $($MyInvocation.ScriptName) -help -full <br \/>&#8221; <\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #000000\">end<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">remarks<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #2b91af\">$examples<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$examplesText<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$remarks<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">exit<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #2b91af\">$full<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$descriptionText<\/span><span style=\"color: #0000ff\">;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$examplesText<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">exit<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\">&nbsp; <br \/><\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #2b91af\">$min<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$descriptionText<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">exit<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #2b91af\">$descriptionText<\/span><span style=\"color: #0000ff\">;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$remarks<span style=\"color: #808080\">&nbsp; <br \/><\/span><span style=\"color: #000000\">exit<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #000000\">end<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">funHelp<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">function<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">function<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">funline<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #2b91af\">$strIN<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #2b91af\">$char<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\"> &#8220;=&#8221;<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #2b91af\">$sColor<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\"> &#8220;Yellow&#8221;<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #2b91af\">$uColor<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\"> &#8220;darkYellow&#8221;<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">[switch]<\/span><span style=\"color: #2b91af\">$help<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #2b91af\">$help<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #2b91af\">$local<\/span><span style=\"color: #000000\">:helpText<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">`<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">@<\/span><span style=\"color: #808080\">&#8221; <br \/>Funline accepts inputs: -strIN for input string and -char for seperator <br \/>-sColor for the string color, and -uColor for the underline color. Only&nbsp; <br \/>the -strIn is required. The others have the following default values: <br \/>-char: =, -sColor: Yellow, -uColor: darkYellow <br \/>Example: <br \/>funline -strIN &#8220;<\/span><span style=\"color: #000000\">Hello<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">world<\/span><span style=\"color: #808080\">&#8221; <br \/>funline -strIn &#8220;<\/span><span style=\"color: #000000\">Morgen<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">welt<\/span><span style=\"color: #808080\">&#8221; -char &#8220;<\/span><span style=\"color: #000000\">&#8211;<\/span><span style=\"color: #808080\">&#8221; -sColor &#8220;<\/span><span style=\"color: #000000\">blue<\/span><span style=\"color: #808080\">&#8221; -uColor &#8220;<\/span><span style=\"color: #000000\">yellow<\/span><span style=\"color: #808080\">&#8221; <br \/>funline -help <br \/>&#8220;<\/span><span style=\"color: #000000\">@<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #2b91af\">$local<\/span><span style=\"color: #000000\">:helpText<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">break<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #000000\">end<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">funline<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">help<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #2b91af\">$strLine<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$char<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">*<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$strIn<\/span><span style=\"color: #000000\">.length<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">Write-Host<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-ForegroundColor<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$sColor<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$strIN<\/span><span style=\"color: #808080\">&nbsp; <br \/><\/span><span style=\"color: #0000ff\">Write-Host<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-ForegroundColor<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$uColor<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$strLine<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #000000\">end<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">funLine<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">function<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Function<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">funWhatIf()<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">foreach<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #2b91af\">$sDomain<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">in<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$Domain<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/>&#8220;what if: Perform operation locate disabled users from the $sDomain domain&#8221; <br \/><\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">exit<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #000000\">end<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">funWhatIf<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Function<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">funQuery()<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">Foreach<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #2b91af\">$sDomain<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">in<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$domain<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #2b91af\">$strOutput<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">Get-WmiObject<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Class<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">win32_useraccount<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-filter<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">`<\/span><span style=\"color: #808080\"> <br \/>&#8220;domain = &#8220;&#8221;$sDomain&#8221;&#8221; AND disabled = &#8216;true'&#8221; <br \/><\/span><span style=\"color: #2b91af\">$count<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #2b91af\">$strOutput<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">|<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">Measure-Object<\/span><span style=\"color: #000000\">).count<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">If<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #2b91af\">$count<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">-eq<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">0<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\">&nbsp; <br \/><\/span><span style=\"color: #000000\">funline<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-scolor<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">green<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-ucolor<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">darkyellow<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-strIN<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">`<\/span><span style=\"color: #808080\"> <br \/>&#8220;There are no disabled accounts in the $sDomain&#8221;&nbsp; <br \/><\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #000000\">end<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">ELSE<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">funline<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-scolor<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">red<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-ucolor<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">darkyellow<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-strIN<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">`<\/span><span style=\"color: #808080\"> <br \/>&#8220;$count disabled in the $sDomain domain &#8212; List follows:&#8221;&nbsp; <br \/><\/span><span style=\"color: #0000ff\">format-table<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-property<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">name,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">sid<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-AutoSize<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-inputobject<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$strOutput<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #000000\">end<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">else<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #000000\">end<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">foreach<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">exit<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #000000\">end<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">funquery<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">#<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Entry<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Point<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #2b91af\">$help<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">funhelp<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #2b91af\">$examples<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">funhelp<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #2b91af\">$full<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">funhelp<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #2b91af\">$whatif<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">funWhatIf<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">(!<\/span><span style=\"color: #2b91af\">$query<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> &#8220;missing parameter&#8221; <\/span><span style=\"color: #0000ff\">;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">funhelp<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #2b91af\">$query<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">funQuery<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\">&nbsp;<\/span> <\/p>\n<\/blockquote>\n<p>When the LocateDisabledUsers.ps1 script runs, the output appears that is shown in the following image. <\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4657.hsg081610021_7E60D31B.jpg\"><img decoding=\"async\" height=\"322\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0458.hsg081610021_thumb_24C2B667.jpg\" alt=\"Image of output of LocateDisabledUsers.ps1 script\" border=\"0\" title=\"Image of output of LocateDisabledUsers.ps1 script\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" \/><\/a> <\/p>\n<p>Later in my <a href=\"http:\/\/www.amazon.com\/Windows-PowerShell-2-0-Best-Practices\/dp\/0735626464\">Windows PowerShell 2.0 Best Practices<\/a> book, I decided to update the script, and I used the <b>[adsiSearcher]<\/b> type accelerator. The output is not exactly the same because I do not return the user&rsquo;s SID. In addition, I display both the disabled user accounts and the accounts that are not disabled, but the concept is basically the same. The FindDisabledUserAccounts.ps1 script is shown here. <\/p>\n<blockquote>\n<p><strong>FindDisabledUserAccounts.ps1<\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<div class=\"code\"><span style=\"color: #0000ff\">#<\/span><span style=\"color: #000000\">Requires<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Version<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">2<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #800000\">0<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #2b91af\">$filter<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\"> &#8220;(&amp;(objectClass=user)(objectCategory=person))&#8221; <br \/><\/span><span style=\"color: #2b91af\">$users<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">([adsiSearcher]<\/span><span style=\"color: #2b91af\">$Filter<\/span><span style=\"color: #000000\">).findall()<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">foreach<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #2b91af\">$suser<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">in<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$users<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\"> <br \/>&#8220;Testing $($suser.properties.item(&#8220;&#8221;distinguishedname&#8221;&#8221;))&#8221; <br \/><\/span><span style=\"color: #2b91af\">$user<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">[adsi]<\/span><span style=\"color: #808080\">&#8220;LDAP:\/\/$($suser.properties.item(&#8220;&#8221;distinguishedname&#8221;&#8221;))&#8221; <br \/><\/span><span style=\"color: #2b91af\">$uac<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #2b91af\">$user<\/span><span style=\"color: #000000\">.psbase.invokeget(<\/span><span style=\"color: #808080\">&#8220;useraccountcontrol&#8221;<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #2b91af\">$uac<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-band<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">0x2)<\/span><span style=\"color: #808080\">&nbsp; <br \/><\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">write-host<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-foregroundcolor<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">red<\/span><span style=\"color: #808080\"> &#8220;`t account is disabled&#8221; <\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\">&nbsp; <br \/><\/span><span style=\"color: #0000ff\">ELSE<\/span><span style=\"color: #808080\">&nbsp; <br \/><\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">write-host<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-foregroundcolor<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">green<\/span><span style=\"color: #808080\"> &#8220;`t account is not disabled&#8221; <\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">#foreach<\/span> <\/div>\n<\/blockquote>\n<p>When the FindDisabledUserAccounts.ps1 script runs, the output appears that is shown in the following image.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8867.hsg081610031_1D3746FA.jpg\"><img decoding=\"async\" height=\"352\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0458.hsg081610031_thumb_516B7040.jpg\" alt=\"Image of output of FindDisabledUserAccounts.ps1 script\" border=\"0\" title=\"Image of output of FindDisabledUserAccounts.ps1 script\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" \/><\/a> <\/p>\n<p>Now with access to the Active Directory <a href=\"http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/tags\/getting+started\/modules\/default.aspx\">module<\/a> from Windows Server 2008 R2 and with my desktop running <a href=\"http:\/\/www.microsoft.com\/windows\/windows-7\/default.aspx\">Windows 7<\/a> with the <a href=\"http:\/\/www.microsoft.com\/downloads\/details.aspx?FamilyID=9ff6e897-23ce-4a36-b7fc-d52065de9960&amp;DisplayLang=en\">RSAT tools<\/a> installed, I can use the <b>Search-ADAccount<\/b> cmdlet. I have not turned this into a script yet because it is basically a single command from a cmdlet. <\/p>\n<p>For a good introduction to using the Active Directory Domain Services Windows 2008 R2 cmdlets, see <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2010\/01\/25\/hey-scripting-guy-january-25-2010.aspx\">Hey, Scripting Guy! What&rsquo;s Up with Active Directory Domain Services Cmdlets?<\/a><\/p>\n<p>At some point, I probably will add support for inputting alternative credentials and support for other domains. But for now, it is a single command:<\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #000000\">Search-ADAccount<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-AccountDisabled<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-UsersOnly<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">|<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">Format-Table<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">name,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">sid<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-AutoSize<\/span> <\/div>\n<\/blockquote>\n<p>When the <b>Search-ADAccount<\/b> command runs, the output appears that is shown in the following image.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0844.hsg081610041_10C923D1.jpg\"><img decoding=\"async\" height=\"322\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1031.hsg081610041_thumb_372B071C.jpg\" alt=\"Image of output of Search-ADAccount command\" border=\"0\" title=\"Image of output of Search-ADAccount command\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" \/><\/a> <\/p>\n<p>From a performance standpoint, which of the three different approaches is best? Let us begin with the WMI Win32_UserAccount script. <\/p>\n<blockquote>\n<p>See <a href=\"http:\/\/blogs.technet.com\/search\/SearchResults.aspx?q=measure-command&amp;sections=7618\">this link for a collection of Hey, Scripting Guy! articles<\/a> that talk about testing the performance of various Windows PowerShell scripts. <\/p>\n<\/blockquote>\n<p>When I use the Measure-Command cmdlet, it takes 571 milliseconds to return. Keep in mind that my AD is small, and I have two domain controllers on my switched gigabyte network.<\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #000000\">Windows<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">PowerShell<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Copyright<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">(C)<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">2010<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Microsoft<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Corporation.<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">All<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">rights<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">reserved.<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">measure-command<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\data\\Windows2008ResKit\\WS08SecurityResKit\\LocateDisabled<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Users.ps1<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-domain<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">nwtraders<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-q<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #800000\">15<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">disabled<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">in<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">the<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">nwtraders<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">domain<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&#8212;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">List<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">follows:<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">====================================================<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Days<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">0<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Hours<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">0<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Minutes<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">0<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Seconds<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">0<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Milliseconds<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">571<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Ticks<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">5719349<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">TotalDays<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">6<\/span><span style=\"color: #000000\">.61961689814815E-06<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">TotalHours<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">0<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #800000\">000158870805555556<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">TotalMinutes<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">0<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #800000\">00953224833333333<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">TotalSeconds<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">0<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #800000\">5719349<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">TotalMilliseconds<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">571<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #800000\">9349<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span> <\/div>\n<\/blockquote>\n<p>I then rebooted my workstation and ran the ADSISearcher script. The reason for rebooting my workstation is to avoid any kind of false performance boosts from ADSI caching. When the script runs, it takes 690 milliseconds to complete. One of the things to keep in mind is that the FindDisabledUserAccounts.ps1 script writes to the Windows PowerShell console, which will increase the amount of time to run the script. <\/p>\n<p>My workstation has solid-state hard drives, and therefore boots really quickly. In fact, if I turn on my workstation and my laptop at the same time, I can be logged into the domain and have Word started before I am even prompted to type in the Windows BitLocker Drive Encryption PIN for my laptop (a prompt that comes up before the Windows 7 even begins to load). To be perfectly honest, if I were to do the testing on my laptop, I probably would forego the additional reboots. <\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">Measure-Command<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\data\\ScriptingGuys\\2010\\HSG_8_16_10\\FindDisabledUserAcco<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">unts.ps1<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">account<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">disabled<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">account<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">disabled<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">account<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">not<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">disabled<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">account<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">not<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">disabled<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">account<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">disabled<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">account<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">disabled<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">account<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">disabled<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">account<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">disabled<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">account<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">disabled<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">account<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">disabled<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">account<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">disabled<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">account<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">disabled<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">account<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">disabled<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">account<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">disabled<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">account<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">disabled<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">account<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">disabled<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">account<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">disabled<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">account<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">not<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">disabled<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">account<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">not<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">disabled<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">account<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">not<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">disabled<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">account<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">not<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">disabled<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">account<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">not<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">disabled<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">account<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">not<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">disabled<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">account<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">not<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">disabled<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">account<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">is<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">not<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">disabled<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Days<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">0<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Hours<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">0<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Minutes<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">0<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Seconds<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">0<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Milliseconds<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">690<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Ticks<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">6904643<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">TotalDays<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">7<\/span><span style=\"color: #000000\">.9914849537037E-06<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">TotalHours<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">0<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #800000\">000191795638888889<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">TotalMinutes<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">0<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #800000\">0115077383333333<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">TotalSeconds<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">0<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #800000\">6904643<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">TotalMilliseconds<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">690<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #800000\">4643<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span> <\/div>\n<\/blockquote>\n<p>I reboot my workstation one more time, and after loading the Active Directory module, I run the <b>Search-ADAccount<\/b> cmdlet command and use the <b>Measure-Command<\/b> cmdlet to time the operation. The results show that it took 81 milliseconds to complete, making it the fastest of the three commands:<\/p>\n<blockquote>\n<p><span style=\"color: #000000\">Windows<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">PowerShell<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Copyright<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">(C)<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">2010<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Microsoft<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Corporation.<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">All<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">rights<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">reserved.<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Import-Module<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">ac<\/span><span style=\"color: #000000\">*<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #0000ff\">PS<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">C:\\&gt;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">measure-command<\/span><span style=\"color: #000000\">{Search-ADAccount<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-AccountDisabled<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-UsersOnly<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">|<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">Format-Table<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">name,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">sid<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-AutoSize<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Days<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">0<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Hours<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">0<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Minutes<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">0<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Seconds<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">0<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Milliseconds<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">81<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">Ticks<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">819660<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">TotalDays<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">9<\/span><span style=\"color: #000000\">.48680555555556E-07<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">TotalHours<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">2<\/span><span style=\"color: #000000\">.27683333333333E-05<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">TotalMinutes<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">0<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #800000\">0013661<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">TotalSeconds<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">0<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #800000\">081966<\/span><span style=\"color: #808080\"> <br \/><\/span><span style=\"color: #000000\">TotalMilliseconds<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">81<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #800000\">966<\/span> <\/p>\n<\/blockquote>\n<p>What does all this tell me? For my environment, any of the three approaches work. And all are virtually the same speed. Keep in mind when using the <b>Measure-Command<\/b> cmdlet that you should be really careful making judgments based upon milliseconds&mdash;it simply is not that accurate. If the results are several seconds apart, you have a guideline to go on. But milliseconds? <a href=\"http:\/\/en.wikipedia.org\/wiki\/Dude\">Dude<\/a>, the antivirus program can kick in and start a scan, or a process can decide to start. Anything can cause a time skew of a few hundred milliseconds. <\/p>\n<p>In addition, you may have other requirements that will dictate which approach you use. The following table summarizes the three different techniques.<\/p>\n<table cellpadding=\"0\" cellspacing=\"0\" border=\"1\">\n<tbody>\n<tr>\n<td width=\"214\" valign=\"top\">\n<p><b>Approach<\/b><\/p>\n<\/td>\n<td width=\"385\" valign=\"top\">\n<p><b>Use<\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"214\" valign=\"top\">\n<p>WMI Win32_UserAccount<\/p>\n<\/td>\n<td width=\"385\" valign=\"top\">\n<p>VBScript, Windows PowerShell 1.0, Windows PowerShell 2.0. If VBScript, then Windows 2000 and later. If Windows PowerShell, then <a href=\"http:\/\/www.microsoft.com\/downloads\/details.aspx?displaylang=en&amp;FamilyID=6ccb7e0d-8f1d-4b97-a397-47bcc8ba3806\">Windows XP<\/a> and later.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"214\" valign=\"top\">\n<p>ADSISearcher<\/p>\n<\/td>\n<td width=\"385\" valign=\"top\">\n<p>Windows PowerShell 2.0, Windows XP, and later on client.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"214\" valign=\"top\">\n<p>Search-ADAccount<\/p>\n<\/td>\n<td width=\"385\" valign=\"top\">\n<p>Windows PowerShell 2.0, Windows 7 with RSAT tools installed, Windows Server 2008 R2 domain controller. <\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>EJ, that is all there is to using Windows PowerShell to search for disabled user accounts. User Management Week will continue tomorrow when we will talk about changing a user&rsquo;s password. <\/p>\n<p>We invite you follow us on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to us at <a href=\"mailto:scripter@microsoft.com\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/social.technet.microsoft.com\/Forums\/en\/ITCG\/threads\/\">Official Scripting Guys Forum.<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p>&nbsp;<\/p>\n<p><b>Ed Wilson and Craig Liebendorfer, Scripting Guys<\/b><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Summary: The Scripting Guys discuss three different approaches to finding disabled user accounts in Active Directory Domain Services by using Windows PowerShell. &nbsp; Hey, Scripting Guy! I would like to use Windows PowerShell to search Active Directory Domain Services (AD DS) for user accounts that are disabled. I had a VBScript script I had [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[7,3,8,20,45],"class_list":["post-17411","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-active-directory","tag-scripting-guy","tag-searching-active-directory","tag-user-accounts","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>&nbsp; Summary: The Scripting Guys discuss three different approaches to finding disabled user accounts in Active Directory Domain Services by using Windows PowerShell. &nbsp; Hey, Scripting Guy! I would like to use Windows PowerShell to search Active Directory Domain Services (AD DS) for user accounts that are disabled. I had a VBScript script I had [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/17411","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\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=17411"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/17411\/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=17411"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=17411"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=17411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}