yo_bee
asked on
Adding attribute values to <not set>
I am trying to setup a VB console app so I can schedule certain updateds to users Attributes.
I have created a simple script that queries all the user and if the CN matches the user it will update the altRecipient attribute from <not set> to a ADsPath.
I am able to clear the attribute, but not able to update.
I was also trying to add arg so I can run this without modifying the code, but this is the second part. I need to get the first part to work. ;)
I have created a simple script that queries all the user and if the CN matches the user it will update the altRecipient attribute from <not set> to a ADsPath.
I am able to clear the attribute, but not able to update.
I was also trying to add arg so I can run this without modifying the code, but this is the second part. I need to get the first part to work. ;)
Imports System.Text.RegularExpressions
Imports System.DirectoryServices
Module Module1
Sub Main()
Const ADS_PROPERTY_CLEAR = 1
Const ADS_PROPERTY_UPDATE = 2
Const ADS_PROPERTY_APPEND = 3
Const ADS_PROPERTY_DELETE = 4
Dim objRootDSE
Dim objSchemaContainer
Dim strSchemaPath
'Get the Root DSE from a random DC'
objRootDSE = GetObject("LDAP://RootDSE")
'Get the Schema NC path for the domain'
strSchemaPath = objRootDSE.Get("defaultNamingContext")
'Connect to the schema container on a random DC'
objSchemaContainer = GetObject("LDAP://" & strSchemaPath)
Dim objSearch As New DirectorySearcher()
objSearch.SearchRoot = New DirectoryEntry(objSchemaContainer)
objSearch.Filter = "(&(objectCategory=user))"
objSearch.SearchScope = SearchScope.Subtree
objSearch.PropertiesToLoad.Add("cn")
objSearch.PropertiesToLoad.Add("distinguishedName")
objSearch.PropertiesToLoad.Add("ADsPath")
Dim colQueryResults As SearchResultCollection
colQueryResults = objSearch.FindAll()
Dim objResult As SearchResult
For Each objResult In colQueryResults
If objResult.Properties("cn")(0) = "<username>" Then
Console.WriteLine(objResult.Properties("cn")(0))
Console.WriteLine(objResult.Properties("distinguishedName")(0))
Console.WriteLine(objResult.Properties("ADsPath")(0))
Dim ObjUser As Object
Dim StrAtt As String
StrAtt = objResult.Properties("ADsPath")(0)
Console.WriteLine(StrAtt)
ObjUser = GetObject(StrAtt)
ObjUser.Putex(ADS_PROPERTY_CLEAR, "altRecipient", "CN=<username>,OU=IT Staff,DC=<domain>,DC=local"))
ObjUser.SetInfo()
End If
Next
End Sub
End Module
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
There's no reason for it to fail. Does it return an error message?
Chris
ASKER
I do get an error, but at the present time I do not have it. When I am able to run this again I will post the error.
That would be good, thanks :)
Chris
Chris
ASKER
I do get an error, but at the present time I do not have it. When I am able to run this again I will post the error.
ASKER
The Put option worked fine.
No Errors
Thanks
Could you help me with my second part of my questions?
No Errors
Thanks
Could you help me with my second part of my questions?
Sure. Have you looked at System.Environment.GetComm
http://msdn.microsoft.com/en-us/library/system.environment.getcommandlineargs.aspx
The example on there is pretty good, it's not really any different from the example I'd give you. Does that go in the direction you need?
Chris
ASKER
Worked perfectly
ASKER