Solved

Missing properties in userPrincipal vb.net for user creation

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

815 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

11 Experts available now in Live!

Get 1:1 Help Now