Every wondered why some queries return much faster than others? If you search on attributes that are indexed, your DC returns the value much quicker. How can you find out what attributes are indexed? use the following :
If you find that your attribute is not being indexed, take a look here to find out how to add it to the index.
If you find that your attribute is not being indexed, take a look here to find out how to add it to the index.
$Collection = @()
$domain = [System.DirectoryServices.ActiveDirectory.domain]::getcurrentdomain()
$ObjectCategory = "attributeSchema"
$ObjectProplist = "name"
$LdapQuery = "(&(objectCategory=$ObjectCategory)(searchFlags:1.2.840.113556.1.4.803:=1))"
($domain).name
$LDAPdomain = [ADSI]('LDAP://CN=Schema,CN=Configuration,dc=' + ($($domain).name -replace "[.]",",dc="))
$Searcher = New-Object System.DirectoryServices.DirectorySearcher($LDAPdomain, $LdapQuery, $ObjectProplist)
$Searcher.pagesize = 1000
$Results = $Searcher.FindAll()
foreach ($Object in $Results){
$Store = "" | select $ObjectProplist
foreach ($prop in $ObjectProplist){
switch ($prop){
lastlogontimestamp {trap { $Store.lastlogontimestamp = "Last Logon value not valid";continue}&{$Store.lastlogontimestamp =[DateTime]::FromFileTimeUTC($Object.Properties.lastlogontimestamp[0])}}
Default {trap { $Store.$prop = "null";continue}&{$Store.$prop = $($Object.Properties.$prop).tostring()}}
}
}
$Collection += $Store
}
$Collection | export-csv "$($domain.name) - indexedattributes.csv" -NoTypeInformation
Comments
Post a Comment