ok, it appears that i have run into a spot that i am not able to
figure out on my own. Let me first say that i have hobbled together
this SUB from things i found on the internet and tutorials. Here is my
issue...I can search AD for the description of the computer and
display it out but am unable to figure out if the
"
If dirEntry.Proper ties.Contains(" description") Then
dirEntry.Proper ties("descripti on")(0) = "Turek, Brett
- Dell Laptop - Modified by VB program"
Else
dirEntry.Proper ties("descripti on").Add("Turek , Brett -
Dell Laptop - Modified by VB program")
End If
dirEntry.Commit Changes()
"
part will actually do what i want, change the description in AD of the
computer. Can anyone look this over and let me know if i am on the
right path? How about some examples of how to change things in AD?
*************** ****
Complete Code:
*************** ****
Imports System
Imports System.Manageme nt
Imports System.Windows. Forms
Imports System.Director yServices
Public Sub Button5_Click(B yVal sender As Object, ByVal e As EventArgs)
Handles Button5.Click
'Rename Machine
'SHELL("NETDOM RENAMECOMPUTER /NewName:" + TextBox3.Text + " /
UserD:domain\us ername /PasswordD:passw ord /Force /Reboot:300")
'Rename Description
Dim userID = "Domain\usernam e"
Dim password = "PASSWORD"
Dim dirEntry As New DirectoryEntry( "LDAP://
OU=Computers,OU =Abingdon,OU=MA R,OU=Customer,D C=us,DC=company ,DC=com",
userID, password)
Dim mySearcher As DirectorySearch er = New
DirectorySearch er(dirEntry)
mySearcher.Filt er = String.Format(" (CN=computerNam e)")
mySearcher.Prop ertiesToLoad.Ad d("cn")
mySearcher.Prop ertiesToLoad.Ad d("description" )
Dim resEnt As SearchResult
resEnt = mySearcher.Find One
If resEnt Is Nothing Then
MsgBox("User not found")
Else
MsgBox("Found: " +
resEnt.GetDirec toryEntry().Pro perties("cn").V alue + " :: " +
resEnt.GetDirec toryEntry().Pro perties("descri ption").Value)
If dirEntry.Proper ties.Contains(" description") Then
dirEntry.Proper ties("descripti on")(0) = "Turek, Brett
- Dell Laptop - Modified by VB program"
Else
dirEntry.Proper ties("descripti on").Add("Turek , Brett -
Dell Laptop - Modified by VB program")
End If
dirEntry.Commit Changes()
MsgBox(resEnt.G etDirectoryEntr y().Properties( "description"). Value)
End If
End Sub
figure out on my own. Let me first say that i have hobbled together
this SUB from things i found on the internet and tutorials. Here is my
issue...I can search AD for the description of the computer and
display it out but am unable to figure out if the
"
If dirEntry.Proper ties.Contains(" description") Then
dirEntry.Proper ties("descripti on")(0) = "Turek, Brett
- Dell Laptop - Modified by VB program"
Else
dirEntry.Proper ties("descripti on").Add("Turek , Brett -
Dell Laptop - Modified by VB program")
End If
dirEntry.Commit Changes()
"
part will actually do what i want, change the description in AD of the
computer. Can anyone look this over and let me know if i am on the
right path? How about some examples of how to change things in AD?
*************** ****
Complete Code:
*************** ****
Imports System
Imports System.Manageme nt
Imports System.Windows. Forms
Imports System.Director yServices
Public Sub Button5_Click(B yVal sender As Object, ByVal e As EventArgs)
Handles Button5.Click
'Rename Machine
'SHELL("NETDOM RENAMECOMPUTER /NewName:" + TextBox3.Text + " /
UserD:domain\us ername /PasswordD:passw ord /Force /Reboot:300")
'Rename Description
Dim userID = "Domain\usernam e"
Dim password = "PASSWORD"
Dim dirEntry As New DirectoryEntry( "LDAP://
OU=Computers,OU =Abingdon,OU=MA R,OU=Customer,D C=us,DC=company ,DC=com",
userID, password)
Dim mySearcher As DirectorySearch er = New
DirectorySearch er(dirEntry)
mySearcher.Filt er = String.Format(" (CN=computerNam e)")
mySearcher.Prop ertiesToLoad.Ad d("cn")
mySearcher.Prop ertiesToLoad.Ad d("description" )
Dim resEnt As SearchResult
resEnt = mySearcher.Find One
If resEnt Is Nothing Then
MsgBox("User not found")
Else
MsgBox("Found: " +
resEnt.GetDirec toryEntry().Pro perties("cn").V alue + " :: " +
resEnt.GetDirec toryEntry().Pro perties("descri ption").Value)
If dirEntry.Proper ties.Contains(" description") Then
dirEntry.Proper ties("descripti on")(0) = "Turek, Brett
- Dell Laptop - Modified by VB program"
Else
dirEntry.Proper ties("descripti on").Add("Turek , Brett -
Dell Laptop - Modified by VB program")
End If
dirEntry.Commit Changes()
MsgBox(resEnt.G etDirectoryEntr y().Properties( "description"). Value)
End If
End Sub
Comment