Create an ADSISearcher object

Hello,

There are severals way to create .Net object from PowerShell.I usually used this one :

$Searcher = [ADSISearcher]'(admincount=1)'
$Searcher.SizeLimit = 5
$Searcher.SearchRoot   = [ADSI]""
$Searcher.FindAll()

But I just discovered a nice new way :

([ADSISearcher]@{
    Filter       = '(admincount=1)'
    SizeLimit    = 5
    SearchRoot   = [ADSI]""
}).FindAll()

You can use a hashtable that contains all needed properties.

This works for all type of objects :

[System.Net.Mail.SmtpClient]@{
    host  = 'smtp.office365.com'
    port  = 587
}

You just need to check on MSDN all the constructor available for the .Net class.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.