Derek
Derek

Reputation: 31

Create Computer in Active Directory

I'm trying to create new computers and add them to OU using vb.net. Everything is fine except the Primary-Group-ID and sAMAccounType attributes. These two attributes show that I'm actually creating users instead of computers so this is the problem.

Here is my code:

Dim oldentry = New DirectoryEntry(SpecificOU, securedusername, securedpassowrd)
Dim newentry As DirectoryEntry = oldentry.Children.Add("CN=" & CumputerName, "Computer")
newentry.Properties("sAMAccountName").Value = "" + CumputerName& "$" + ""

newentry.CommitChanges()
newentry.Close()
newentry.Dispose()

I can find the computer created but the only difference is that this "computer" is actually normal user account. Since I cannot set the properties for primaryGroupID and sAMAccountType, I don't know what to do right now.

Upvotes: 2

Views: 245

Answers (1)

Derek
Derek

Reputation: 31

Okay I figured it out. I need to add one more property so it now works

newentry.Properties("userAccountControl").Value = &H1020

&H1020 is equivalent to 0x1020 in hex format, which means workstation trusted account and password not required. Value will vary depending on specific circumstances. https://support.microsoft.com/en-ca/help/305144/how-to-use-the-useraccountcontrol-flags-to-manipulate-user-account-pro

Upvotes: 1

Related Questions