Solved

Missing properties in userPrincipal vb.net for user creation

Posted on 2010-08-28
5
1,691 Views
Last Modified: 2012-05-10
I'm moving over a .vbs script to a vb.net compiled applciation.  I got the following code to work ok:
            pcContext = New PrincipalContext(ContextType.Domain, "mine.local", "ou=2022,dc=mine,dc=local", "administrator", "mypassword!!") 
            upUser = New UserPrincipal(pcContext)
            upUser.SamAccountName = szSAMAcctName
            upUser.GivenName = szFirst
            upUser.Surname = szLast
            upUser.MiddleName = szMiddle
            upUser.Description = szDescription
            upUser.HomeDirectory = szHomeDirectory
            upUser.DisplayName = szDisplayName
            upUser.EmployeeId = szID
            'upUser.
            upUser.Enabled = True
            'upUser.postalCode = szID
            upUser.Save()

Open in new window


And it creates the new user perfectly.  However, I need to use other fields in AD that show in active directory users and computers like office.  In VBSCript the field is called physicalDeliveryOfficeName but that field is not listed nor is there anything close to it.  The other field I want to use is postalCode.

How can I update these fields when I create the user?
0
Comment
Question by:sej69
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 4

Expert Comment

by:kjetilroe
ID: 33552327

I am assuming you are using .Net Framework 3.5 or newer, there you can use the ExtensionGet funktion to get any custom fields from the UserPrincipal object.

upUser.ExtensionGet("physicalDeliveryOfficeName")
upUser.ExtensionGet("postalCode")

You might have to check for null on the returnvalue in case no attribute exist for this name.

If not, here is a link to somebody who have done something similar in .Net Framework 2.0, that might help you on the right track:

http://www.vbforums.com/showthread.php?t=403284
0
 

Author Comment

by:sej69
ID: 33552848
I'm using .net 4.0.  How do I write to those fields?
0
 
LVL 4

Expert Comment

by:kjetilroe
ID: 33554464

My advice is that you set a breakpoint after creating the object, and explore your fields and fieldnames through the debugger.
0
 

Accepted Solution

by:
sej69 earned 0 total points
ID: 33557762
I tried that...  They just aren't there...  I ddi find a reference to setting these properties outside of the creation of the object but I as of yet need to find the functions to do so.  With that said, I decided to bite the bullet and learn C#.  For some odd reason, I was able to write all the properties without issue during the user creation process.  ... I should have just went to C# but I thought it was going to be a lot different than C/C++ (it is some but not a lot).
0
 
LVL 4

Expert Comment

by:kjetilroe
ID: 33557805

Yes, C# is very similar to C++, so it is not a very big jump to go to C# instead of C++, except for all the extra functionality you get by going to C#.
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

689 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question