Hmm maybe i misread your response.. I'll try to execute the method after I close the ClrNew paranthesis and let you know how it goes.
As far as .net versus com versus winbatch adsi extender.
I didn't delve into COM much (i'm more familiar with Winbatch and Powershell, so .NET was more appealing)
At least as far as the extender is concerned it can't keep up with the performance.
My application searches for about 10000 objects a day
it then interrogates about 30 attributes each.
The Extender was just much slower than the .NET objects that both search and return properties in one call (now one call to me, admittedly on the wire it might be several calls)
Also the .NET objects can return the objects presorted based on any Property...
Aaron
Ok I cant figure it out
Here is a workign Powershell
[System.Reflection.Assembly]::LoadWithPartialName("System.DirectoryServices")
[System.Reflection.Assembly]::LoadWithPartialName("System.DirectoryServices.AccountManagement")
#there are easier ways to do this in powershell, however i choose this because it calls constructors just like winbatch would.. 1 is the Constant For ContextType.Domain
$context = New-Object -TypeName System.DirectoryServices.AccountManagement.PrincipalContext(1,"corp.xxxxxxxx.loc")
$thisuser = [System.DirectoryServices.AccountManagement.UserPrincipal]::FindByIdentity($context, "a_valid_samaccountname")
PS C:\Windows\system32> $thisuser
GivenName : -----n
MiddleName :
Surname : ------h
EmailAddress : -------h@b-------.com
VoiceTelephoneNumber : ###-####
EmployeeId : ####
AdvancedSearchFilter : System.DirectoryServices.AccountManagement.AdvancedFilters
Enabled : True
AccountLockoutTime :
LastLogon : 7/8/2015 4:59:26 PM
PermittedWorkstations : {}
PermittedLogonTimes : {255, 255, 255, 255...}
AccountExpirationDate :
SmartcardLogonRequired : False
DelegationPermitted : True
BadLogonCount : 0
HomeDirectory : \\XXXXX\Home\Security\XXXXX
HomeDrive : X:
ScriptPath :
LastPasswordSet : 7/9/2015 6:18:29 PM
LastBadPasswordAttempt : 7/14/2015 5:32:55 PM
PasswordNotRequired : False
PasswordNeverExpires : False
UserCannotChangePassword : False
AllowReversiblePasswordEncryption : False
Certificates : {[Subject]
CN=XXXX XXXXX
[Issuer]
CN=XXXXXXXXXXXXXXXXXXX
[Serial Number]
613CB5130002000073F7
[Not Before]
4/17/2015 3:10:58 PM
[Not After]
4/16/2017 3:10:58 PM
[Thumbprint]
D461734FA0019FBF8AD4C2DEAC939730F6DE8352
}
Context : System.DirectoryServices.AccountManagement.PrincipalContext
ContextType : Domain
Description : XX - XXXXX
DisplayName : AXXXX GXXXX
SamAccountName : gXXXXX
UserPrincipalName : gXXXXXX@XXXXXX.com
Sid : S-1-5-21-2795705288-3334924005-23762XXXXX-1XXXX
Guid : cb96a1cf-d6bb-43ad-XXXX-1693cf439a5a
DistinguishedName : CN=AXXXXXXX,OU=Users,OU=Information Services,OU=Divisions,DC=XXXX,DC=XXXX,DC=XXXXX
StructuralObjectClass : user
What i tried in WinBatch
;ObjectClrOption("version","v4.0.30319")
ObjectClrOption ("use","System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
ObjectClrOption ("use","System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
ObjectClrOption ("use","System.DirectoryServices.AccountManagement, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
ObjectClrOption ("use","System.Net, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
ObjectClrOption ("use","System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
ObjectClrOption ("use","System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
ObjectClrOption ("use","System.IO, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
;ObjectClrOption ("use","System.Numerics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
;BigInteger
MACHINECONSTANT = 0
DOMAINCONSTANT = 1
CType = ObjectClrNew("System.DirectoryServices.AccountManagement.ContextType",MACHINECONSTANT) ; i know this works from other code
DType = ObjectClrNew("System.DirectoryServices.AccountManagement.ContextType",DOMAINCONSTANT) ; i know this works from other code
ThisContext = ObjectClrNew("System.DirectoryServices.AccountManagement.PrincipalContext",DType,"corp.xxxxxxx.loc"); i know this works from other code
;ThisUser = ObjectClrNew("System.DirectoryServices.AccountManagement.UserPrincipal",ThisContext)(::FindByIdentity(ThisContext,"a_valid_samaccountname"))
;ThisUser = ObjectClrNew("System.DirectoryServices.AccountManagement.UserPrincipal",ThisContext)::FindByIdentity(ThisContext,"a_valid_samaccountname")
;ThisUser = ObjectClrNew("System.DirectoryServices.AccountManagement.UserPrincipal",ThisContext)(FindByIdentity(ThisContext,"a_valid_samaccountname"))
;ThisUser = ObjectClrNew("System.DirectoryServices.AccountManagement.UserPrincipal",ThisContext)FindByIdentity(ThisContext,"a_valid_samaccountname")
;ThisUser = ObjectClrNew("System.DirectoryServices.AccountManagement.UserPrincipal",ThisContext).FindByIdentity(ThisContext,"a_valid_samaccountname")
;ThisUser = ObjectClrNew("System.DirectoryServices.AccountManagement.UserPrincipal",ThisContext),FindByIdentity(ThisContext,"a_valid_samaccountname")
;ThisUser = ObjectClrNew("System.DirectoryServices.AccountManagement.UserPrincipal")(::FindByIdentity(ThisContext,"a_valid_samaccountname"))
;ThisUser = ObjectClrNew("System.DirectoryServices.AccountManagement.UserPrincipal")::FindByIdentity(ThisContext,"a_valid_samaccountname")
;ThisUser = ObjectClrNew("System.DirectoryServices.AccountManagement.UserPrincipal")(FindByIdentity(ThisContext,"a_valid_samaccountname"))
;ThisUser = ObjectClrNew("System.DirectoryServices.AccountManagement.UserPrincipal",ThisContext)FindByIdentity(ThisContext,"a_valid_samaccountname")
;ThisUser = ObjectClrNew("System.DirectoryServices.AccountManagement.UserPrincipal").FindByIdentity(ThisContext,"a_valid_samaccountname")
;ThisUser = ObjectClrNew("System.DirectoryServices.AccountManagement.UserPrincipal"),FindByIdentity(ThisContext,"a_valid_samaccountname")
;ThisUser = ObjectClrNew("System.DirectoryServices.AccountManagement.UserPrincipal",'FindByIdentity(ThisContext,"a_valid_samaccountname")')
;ThisUser = ObjectClrNew("System.DirectoryServices.AccountManagement.UserPrincipal",'FindByIdentity',ThisContext,"a_valid_samaccountname")
ThisUser = ObjectClrNew("System.DirectoryServices.AccountManagement.UserPrincipal",'FindByIdentity(' : ThisContext : ',"a_valid_samaccountname")')
Could not get it to work