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
Solved

Missing properties in userPrincipal vb.net for user creation

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…
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…

828 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