{"id":17331,"date":"2010-08-24T00:01:00","date_gmt":"2010-08-24T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2010\/08\/24\/use-the-powershell-adsisearcher-type-accelerator-to-search-active-directory\/"},"modified":"2010-08-24T00:01:00","modified_gmt":"2010-08-24T00:01:00","slug":"use-the-powershell-adsisearcher-type-accelerator-to-search-active-directory","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/use-the-powershell-adsisearcher-type-accelerator-to-search-active-directory\/","title":{"rendered":"Use the PowerShell [adsiSearcher] Type Accelerator to Search Active Directory"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p><strong>Summary<\/strong>: Learn how to use the Windows PowerShell [adsiSearcher] type accelerator to search Active Directory Domain Services (AD DS).    <\/p>\n<p><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\" \/> Hey, Scripting Guy! I am trying to get in touch with my inner programmer. The problem is that our company has cut head count in the past two years, and the remaining staff (myself included) is afraid to say no to anything, or to complain about too much work. The result has been many 12-hour days over the last two years. Training budget? Ha! That flew out the window months before the first pink slip arrived. So, I am struggling with attempting to learn a new skill, with no money for formal classes, or even to purchase a good book on the subject. While searching on the internet to learning about using Windows PowerShell to search Active Directory, I ran across your web site, but something confuses me. It seems that you use random methods to search AD, and I do not understand how you can use something in square brackets and it magically seems to work. How about starting from the beginning, I have been in IT for more than 30 years, so you can assume that I am mediocre, but trainable.<\/p>\n<p>&#8212; BB<\/p>\n<p>&nbsp;<\/p>\n<p><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\" \/> Hello BB, <\/p>\n<p>Microsoft Scripting Guy Ed Wilson here. Craig sent me a link to a really good deal on tea this afternoon. It seems that my favorite e-commerce web site was running a special on tea today. Far out; those kind of things seem like a ray of sunshine, on an otherwise cloudy day. I was in the middle of a cup of rather generic tea with some lotus blossoms, <a href=\"http:\/\/en.wikipedia.org\/wiki\/Cinnamon\">cinnamon<\/a>, <a href=\"http:\/\/en.wikipedia.org\/wiki\/Cymbopogon\">lemon grass<\/a>, and a single <a href=\"http:\/\/en.wikipedia.org\/wiki\/Pine\">pine<\/a> needle (I like coming up with my own combinations of tea) with a plate of <a href=\"http:\/\/en.wikipedia.org\/wiki\/Tim_Tam\">Tim Tams<\/a> and raw <a href=\"http:\/\/en.wikipedia.org\/wiki\/Walnut\">walnuts<\/a>. The Blues Brothers were wailing from my <a href=\"http:\/\/zune.net\/en-us\/products\/zunehd\/default.htm\">Zune HD<\/a>, and I was experimenting with Windows PowerShell when the Communicator on my laptop went off. It was Craig and the aforementioned good deal on tea &ndash;yes, I was interested! It is really cool to have good friends that look out for your best interests. <\/p>\n<p>BB, I will be your friend. I can&rsquo;t believe I never really explained the adsisearcher square brackets (as opposed to sponges who wear square pants). Well, let&rsquo;s dive in. <\/p>\n<p>When using the [adsiSearcher] type accelerator, you can create an instance of the class by supplying the constructor to it directly on the same line. You do not use the New-Object cmdlet. For example, if you attempt to use the New-Object cmdlet to create an instance of the class, the error shown in the following image is displayed.&nbsp; <\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4760.HSG08241001_2A844AB9.jpg\"><img decoding=\"async\" height=\"424\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8407.HSG08241001_thumb_433371FC.jpg\" alt=\"Image of error shown when attempting to use New-Object cmdlet\" border=\"0\" title=\"Image of error shown when attempting to use New-Object cmdlet\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" \/><\/a> <\/p>\n<p>Typing [adsiSearcher] in the Windows PowerShell console, and pressing enter tells you the type accelerator is recognized, and that it will work, but it does not create an instance of the class &ndash; i.e., there is no constructor. Piping the type accelerator to the format-list cmdlet and asking for all the properties to be returned, supplies lots of cool information about the class, but does not return the information we saw when we used the new-object cmdlet to create the DirectorySearcher class. The details returned via the format-list cmdlet are seen here. <\/p>\n<blockquote>\n<p><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\">[adsisearcher]<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsPublic<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">IsSerial<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Name<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">BaseType<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">&#8212;&#8212;&#8211;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&#8212;&#8212;&#8211;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&#8212;-<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&#8212;&#8212;&#8211;<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">True<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">DirectorySearcher<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">System.ComponentModel&#8230;.<\/span><span style=\"color: #808080\">       <\/p>\n<p><\/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\">[adsisearcher]<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">|<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">fl<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">*<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">Module<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">System.DirectoryServices.dll<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">Assembly<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">System.DirectoryServices,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Version<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #800000\">2<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #800000\">0<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #800000\">0<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #800000\">0<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Culture<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\">neut<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">ral,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">PublicKeyToken<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\">b03f5f7f11d50a3a<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">TypeHandle<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">System.RuntimeTypeHandle<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">DeclaringMethod<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">BaseType<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">System.ComponentModel.Component<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">UnderlyingSystemType<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">System.DirectoryServices.DirectorySearcher<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">FullName<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">System.DirectoryServices.DirectorySearcher<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">AssemblyQualifiedName<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">System.DirectoryServices.DirectorySearcher,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">System.Dire<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">ctoryServices,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Version<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #800000\">2<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #800000\">0<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #800000\">0<\/span><span style=\"color: #000000\">.<\/span><span style=\"color: #800000\">0<\/span><span style=\"color: #000000\">,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Culture<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\">neutral,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Public<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">KeyToken<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\">b03f5f7f11d50a3a<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">Namespace<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">System.DirectoryServices<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">GUID<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">9ea63a6d-7480-31a3-ac60-1b358a0655a7<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">GenericParameterAttributes<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsGenericTypeDefinition<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsGenericParameter<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">GenericParameterPosition<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsGenericType<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">ContainsGenericParameters<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">StructLayoutAttribute<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">System.Runtime.InteropServices.StructLayoutAttribute<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">Name<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">DirectorySearcher<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">MemberType<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">TypeInfo<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">DeclaringType<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">ReflectedType<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">MetadataToken<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #800000\">33554466<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">TypeInitializer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Void<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">.cctor()<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsNested<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">Attributes<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">AutoLayout,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">AnsiClass,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Class,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Public,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">HasSecurity,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Befo<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">reFieldInit<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsVisible<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">True<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsNotPublic<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsPublic<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">True<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsNestedPublic<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsNestedPrivate<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsNestedFamily<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsNestedAssembly<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsNestedFamANDAssem<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsNestedFamORAssem<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsAutoLayout<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">True<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsLayoutSequential<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsExplicitLayout<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsClass<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">True<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsInterface<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsValueType<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsAbstract<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsSealed<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsEnum<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsSpecialName<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsImport<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsSerializable<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsAnsiClass<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">True<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsUnicodeClass<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsAutoClass<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsArray<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsByRef<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsPointer<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsPrimitive<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsCOMObject<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">HasElementType<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsContextful<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsMarshalByRef<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">True<\/span> <\/p>\n<\/blockquote>\n<p>To create an instance of the DirectorySearcher class using the type accelerator, you can supply a set of empty strings as seen here.<\/p>\n<blockquote>\n<p><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\">[adsisearcher]<\/span><span style=\"color: #808080\">&#8220;&#8221;       <br \/><\/span><span style=\"color: #000000\">CacheResults<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">True<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">ClientTimeout<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-00:<\/span><span style=\"color: #800000\">00<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #800000\">01<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">PropertyNamesOnly<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">Filter<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">PageSize<\/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\">PropertiesToLoad<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{}<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">ReferralChasing<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">External<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">SearchScope<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Subtree<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">ServerPageTimeLimit<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-00:<\/span><span style=\"color: #800000\">00<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #800000\">01<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">ServerTimeLimit<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-00:<\/span><span style=\"color: #800000\">00<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #800000\">01<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">SizeLimit<\/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\">SearchRoot<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">System.DirectoryServices.DirectoryEntry<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #0000ff\">Sort<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">System.DirectoryServices.SortOption<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">Asynchronous<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">Tombstone<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">AttributeScopeQuery<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">DerefAlias<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Never<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">SecurityMasks<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">None<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">ExtendedDN<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">None<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">DirectorySynchronization<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">VirtualListView<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">Site<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">Container<\/span><span style=\"color: #808080\">&nbsp;<\/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> <\/p>\n<\/blockquote>\n<p>There is only one problem, and that is that no search filter has been supplied. This is a major source of confusion for people attempting to use the [adsisearcher] type accelerator; and it is especially true when people are used to the behavior of the new-object cmdlet \/ no constructor syntax that was examined earlier. Remember, that when one string value is supplied to the DirectorySearcher class for a constructor the value is interpreted as the filter. Therefore, [adsisearcher]&rdquo;&rdquo; specifies a filter that has no characters in it. The good thing is that the searchroot is automatically set to the root of the current domain. This is seen here.<\/p>\n<blockquote>\n<p><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: #2b91af\">$a<\/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: #808080\">&#8220;&#8221;       <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: #2b91af\">$a<\/span><span style=\"color: #000000\">.Filter<\/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: #2b91af\">$a<\/span><span style=\"color: #000000\">.SearchRoot<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">distinguishedName<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{DC<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\">NWTraders,DC<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\">Com}<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">Path<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">LDAP:\/\/DC<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\">NWTraders,DC<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\">Com<\/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> <\/p>\n<\/blockquote>\n<p>With the new-object cmdlt and no constructor the &ldquo;objectcategory=*&rdquo; filter is created. But when [adsisearcher&rsquo;&rdquo;&rdquo; is used, we have specifically created an instance of the DirectorySearcher class with no filter. There is no way, (that I know of. If you find a way, email me at <a href=\"mailto:scripter@microsoft.com\">scripter@microsoft.com<\/a>) to create an instance of the DirectorySearcher class, using the [adsisearcher] type accelerator by supplying no constructor. With no filter, an error is returned when attempting to call the findone() method. This is seen here.<\/p>\n<blockquote>\n<p><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: #2b91af\">$a<\/span><span style=\"color: #000000\">.FindOne()<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">Exception<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">calling<\/span><span style=\"color: #808080\"> &#8220;FindOne&#8221; <\/span><span style=\"color: #000000\">with<\/span><span style=\"color: #808080\"> &#8220;0&#8221; <\/span><span style=\"color: #000000\">argument(s):<\/span><span style=\"color: #808080\"> &#8220;The search filter is invalid.&#8221;       <br \/><\/span><span style=\"color: #000000\">At<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">line:<\/span><span style=\"color: #800000\">1<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">char:<\/span><span style=\"color: #800000\">11<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">+<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$a<\/span><span style=\"color: #000000\">.FindOne<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&lt;&lt;&lt;&lt;<\/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\">&nbsp;<\/span><span style=\"color: #000000\">CategoryInfo<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">NotSpecified:<\/span><span style=\"color: #808080\">&nbsp;<\/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\">MethodInvocationException<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">+<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">FullyQualifiedErrorId<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">DotNetMethodException<\/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> <\/p>\n<\/blockquote>\n<p>It is not that different objects are being created; the same object is created. This is seen here. <\/p>\n<blockquote>\n<p><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\">([adsisearcher]<\/span><span style=\"color: #808080\">&#8220;&#8221;<\/span><span style=\"color: #000000\">).gettype()<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsPublic<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">IsSerial<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Name<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">BaseType<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">&#8212;&#8212;&#8211;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&#8212;&#8212;&#8211;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&#8212;-<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">True<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">DirectorySearcher<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">System.ComponentModel<\/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\">([adsisearcher]<\/span><span style=\"color: #808080\">&#8220;name=bob&#8221;<\/span><span style=\"color: #000000\">).gettype()<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">IsPublic<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">IsSerial<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Name<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">BaseType<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">&#8212;&#8212;&#8211;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&#8212;&#8212;&#8211;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&#8212;-<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">True<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">False<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">DirectorySearcher<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">System.ComponentModel&#8230;.<\/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> <\/p>\n<\/blockquote>\n<p>It is, of course, possible to add a filter, and then to call the method. This is seen here.<\/p>\n<blockquote>\n<p><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: #2b91af\">$a<\/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: #808080\">&#8220;&#8221;       <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: #2b91af\">$a<\/span><span style=\"color: #000000\">.Filter<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\"> &#8220;name=bob&#8221;       <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: #2b91af\">$a<\/span><span style=\"color: #000000\">.FindOne()<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">Path<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Properties<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">&#8212;-<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&#8212;&#8212;&#8212;-<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">LDAP:\/\/CN<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\">bob,OU<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\">HSG_TestOU,DC<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\">NWTrader&#8230;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{primarygroupid,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">msexchpoliciesinclude&#8230;<\/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> <\/p>\n<\/blockquote>\n<p>The problem is this is simply extra work. Because of this confusion, some bloggers have advocated simply not using the [adsisearcher] type accelerator, and always using New-Object to create the DirectorySearcher class. However, the goal is to do less work, not more, and in this case, the answer is easy. Supply the search filter when creating the class instance. The reason for creating an instance of the DirectorySearcher is that you are interested in searching for something; therefore, you will always have some sort of filter in mind.<\/p>\n<p>If you want to use the default search filter that is created by the New-Object technique, use the &ldquo;objectcategory=*&rdquo; filter. This is seen here.<\/p>\n<blockquote>\n<p><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: #2b91af\">$a<\/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: #808080\">&#8220;objectcategory=*&#8221;       <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: #2b91af\">$a<\/span><span style=\"color: #000000\">.Filter<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">objectcategory<\/span><span style=\"color: #0000ff\">=<\/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: #2b91af\">$a<\/span><span style=\"color: #000000\">.SearchRoot<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">distinguishedName<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{DC<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\">NWTraders,DC<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\">Com}<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">Path<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">:<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">LDAP:\/\/DC<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\">NWTraders,DC<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\">Com<\/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> <\/p>\n<\/blockquote>\n<p>Because the DirectorySearcher object is created by using the [adsisearcher] type accelerator, and the filter is specified in the constructor, there is no need to store the intervening object in a variable. The intervening variable methodology is seen here. <\/p>\n<blockquote>\n<p><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: #2b91af\">$a<\/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: #808080\">&#8220;objectcategory=computer&#8221;       <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: #2b91af\">$a<\/span><span style=\"color: #000000\">.FindOne()<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">Path<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Properties<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">&#8212;-<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&#8212;&#8212;&#8212;-<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">LDAP:\/\/CN<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\">HYPERV,OU<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\">Domain<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Controllers,&#8230;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{primarygroupid,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">iscriticalsystemobjec&#8230;<\/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> <\/p>\n<\/blockquote>\n<p>The DirectorySearcher object is stored in the $a variable, and then the FindOne() method is called. To avoid the intervening variable, you can use a pair of parentheses to force evaluation of the first line of code. Once the DirectorySearcher object is created, the FindOne() method can be called. This is seen here. <\/p>\n<blockquote>\n<p><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\">([adsisearcher]<\/span><span style=\"color: #808080\">&#8220;objectcategory=computer&#8221;<\/span><span style=\"color: #000000\">).FindOne()<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">Path<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Properties<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">&#8212;-<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">&#8212;&#8212;&#8212;-<\/span><span style=\"color: #808080\">       <br \/><\/span><span style=\"color: #000000\">LDAP:\/\/CN<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\">HYPERV,OU<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\">Domain<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Controllers,&#8230;<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">{primarygroupid,<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">iscriticalsystemobjec&#8230;<\/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> <\/p>\n<\/blockquote>\n<p>The FindAll() method can also be called directly. This is shown in the following image.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4452.HSG08241002_54A3D2D4.jpg\"><img decoding=\"async\" height=\"372\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2627.HSG08241002_thumb_6CC73D2F.jpg\" alt=\"Image of FindAll() method being called directly\" border=\"0\" title=\"Image of FindAll() method being called directly\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" \/><\/a> <\/p>\n<p>&nbsp;<\/p>\n<p>BB, that is all there is to using the [adsisearcher] type accelerator. Searching Active Directory Domain Services week will continue tomorrow when we talk about <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/scripts\/ad\/search\/default.mspx?mfr=true\">searching AD<\/a> DS for computers, and pinging them to see if they are up. We would love for you to follow us on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\">Twitter<\/a> or <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 them 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><strong>Ed Wilson and Craig Liebendorfer, Scripting Guys<\/strong><\/p>\n<p><strong><br \/><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Summary: Learn how to use the Windows PowerShell [adsiSearcher] type accelerator to search Active Directory Domain Services (AD DS). Hey, Scripting Guy! I am trying to get in touch with my inner programmer. The problem is that our company has cut head count in the past two years, and the remaining staff (myself included) [&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,51,3,4,8,45],"class_list":["post-17331","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-active-directory","tag-getting-started","tag-scripting-guy","tag-scripting-techniques","tag-searching-active-directory","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>&nbsp; Summary: Learn how to use the Windows PowerShell [adsiSearcher] type accelerator to search Active Directory Domain Services (AD DS). Hey, Scripting Guy! I am trying to get in touch with my inner programmer. The problem is that our company has cut head count in the past two years, and the remaining staff (myself included) [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/17331","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=17331"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/17331\/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=17331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=17331"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=17331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}