I need help in moving user in active directory

Asked By 10 points N/A Posted on -
qa-featured

How to move user in active directory console from one OU to another? I need a little help with this.

Thanks.

SHARE
Best Answer by Allen Kenneth
Answered By 0 points N/A #102109

I need help in moving user in active directory

qa-featured

 

You have to follow the process below I given. It’s a easy process if everything goes well with your activities to do it.
 
At first you have to add user into other OU by following this and done-
 
PublicSubAddToGroup(ByValuserDn AsString,ByValgroupDn AsString)
 
Try
 
DimdirEntry AsDirectoryEntry=NewDirectoryEntry(("LDAP://"+groupDn))
 
dirEntry.Properties("member").Add(userDn)
 
dirEntry.CommitChanges
 
dirEntry.Close
 
CatchE AsSystem.DirectoryServices.DirectoryServicesCOMException
 
doSomething with E.Message.ToString();
 
End Try
 
End Sub
 
 
Now you must have to remove from previous OU by doing this-
 
PublicSubRemoveUserFromGroup(ByValuserDn AsString,ByValgroupDn AsString)
 
Try
 
DimdirEntry AsDirectoryEntry=NewDirectoryEntry(("LDAP://"+groupDn))
 
dirEntry.Properties("member").Remove(userDn)
 
dirEntry.CommitChanges
 
dirEntry.Close
 
CatchE AsSystem.DirectoryServices.DirectoryServicesCOMException
 
doSomething with E.Message.ToString();
 
End Try
 
End Sub
 
Also you can use code translator for fill up your purposes. This may be work more efficiently for you
 

Or you may also try this:

VB to C++ Converter Free Edition

 
Wish you will be get rid.
Best Answer
Best Answer
Answered By 0 points N/A #102110

I need help in moving user in active directory

qa-featured

 

Hello Ava,

 

Use the code given below to move a user in the active directory console from one OU to a separate OU.
 
1) You have to add the user to the other OU first. Follow this code section

Public Sub AddToGroup(ByVal userDn As String, ByVal groupDn As String)
        Try
            Dim dirEntry As DirectoryEntry = New DirectoryEntry(("LDAP://" + groupDn))
            dirEntry.Properties("member").Add(userDn)
            dirEntry.CommitChanges
            dirEntry.Close
        Catch E As System.DirectoryServices.DirectoryServicesCOMException
            'doSomething with E.Message.ToString();
        End Try
    End Sub

2) Then you have to remove the user from previous OU.
 
 
Public Sub RemoveUserFromGroup(ByVal userDn As String, ByVal groupDn As String)
        Try 
            Dim dirEntry As DirectoryEntry = New DirectoryEntry(("LDAP://" + groupDn))
            dirEntry.Properties("member").Remove(userDn)
            dirEntry.CommitChanges
            dirEntry.Close
        Catch E As System.DirectoryServices.DirectoryServicesCOMException
            'doSomething with E.Message.ToString();
        End Try
    End Sub

Follow this for more info: http://forums.asp.net/t/1614982.aspx

 

Login/Register to Answer

Related Questions