Solved

Missing properties in userPrincipal vb.net for user creation

Posted on 2010-08-28
5
1,625 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
  • 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now