active directory - VB.net creating new AD user account using UserPrincipalEx? -
active directory - VB.net creating new AD user account using UserPrincipalEx? -
i'm having heck of time trying add together fields section , title.
i'm using create user account:
dim ctx new principalcontext(contexttype.domain, "domain.name.pvt", "ou=users,dc=global,dc=pvt") dim usr userprincipal = new userprincipal(ctx)
i have no problem creating business relationship can't add together simple things department
, title
. read using extensions in c++ , have no clue on how it.
any help great!!! thanks!
if you're on .net 3.5 , up, should check out system.directoryservices.accountmanagement
(s.ds.am) namespace. read here:
to extend userprincipal
class, don't need much - suffice (i wrote in c# , converted vb.net on 'net - hope there's no issues vb.net code!)
imports system.directoryservices.accountmanagement namespace adextended <directoryrdnprefix("cn")> _ <directoryobjectclass("person")> _ public class userprincipalex inherits userprincipal ' inplement constructor using base of operations class constructor. public sub new(context principalcontext) mybase.new(context) end sub ' implement constructor initialization parameters. public sub new(context principalcontext, samaccountname string, password string, enabled boolean) mybase.new(context, samaccountname, password, enabled) end sub ' create "department" property. <directoryproperty("department")> _ public property department() string if extensionget("department").length <> 1 homecoming string.empty end if homecoming directcast(extensionget("department")(0), string) end set extensionset("department", value) end set end property ' create "title" property. <directoryproperty("title")> _ public property title() string if extensionget("title").length <> 1 homecoming string.empty end if homecoming directcast(extensionget("title")(0), string) end set extensionset("title", value) end set end property ' implement overloaded search method findbyidentity. public shared shadows function findbyidentity(context principalcontext, identityvalue string) userprincipalex homecoming directcast(findbyidentitywithtype(context, gettype(userprincipalex), identityvalue), userprincipalex) end function ' implement overloaded search method findbyidentity. public shared shadows function findbyidentity(context principalcontext, identitytype identitytype, identityvalue string) userprincipalex homecoming directcast(findbyidentitywithtype(context, gettype(userprincipalex), identitytype, identityvalue), userprincipalex) end function end class end namespace
now, utilize userprincipalex
class:
dim ctx new principalcontext(contexttype.domain, "domain.name.pvt", "ou=users,dc=global,dc=pvt") dim usr userprincipalex = new userprincipalex(ctx) usr.title = "......." usr.department = "......."
the new s.ds.am makes easy play around users , groups in ad!
vb.net active-directory directoryservices
Comments
Post a Comment