Cannot access Active Directroy Ou after Creation RRS feed

  • Question

  • User775589824 posted

    I am creating a new OU each time I move user whom have not logged in for a long time and move them to it.  I am able to create the OU but then via Vb.net cannot access keep getting perparation error.  The 1st is my creation of the New OU and it has the 2 dates of created and delete on.  I think it is simply becuase I put in spaces and slashs in the OU becuase I can get ahold of other OU' no no slashes or spaces no problem.  Is there switches to through in here to recognize this?

    Dim OU As String = "Created on " & Date.Today & " Delete On" & DateAdd(DateInterval.Day, 45, Date.Today)
     Public Shared Function CreateOU(ByVal OU As String) As Boolean
            Dim oD As DirectoryEntry
            Dim oOU As DirectoryEntry
                oD = New DirectoryEntry(Disabled, LDAPUser, LDAPPass, DirectoryServices.AuthenticationTypes.Secure)
                oOU = oD.Children.Add(String.Format("ou={0}", OU), "OrganizationalUnit")
                Return True
            Catch ex As Exception
                Return False
            End Try
        End Function


    Now getting at it is the problem, disabling the user works fine but then moveing them is the problem as it does not see the New OU.

     Public Shared Function Disable(ByVal Username As String, ByVal OU As String) As Boolean
            Dim DirEntry As DirectoryEntry = New DirectoryEntry(OUUsers, LDAPUser, LDAPPass, DirectoryServices.AuthenticationTypes.Secure)
            Dim oSearcher As DirectorySearcher = New DirectorySearcher(DirEntry)
            Dim result As SearchResult
            Dim DisabledOu As String = "LDAP://myLdap/ou=" & OU & ",RestLdap"
            oSearcher.Filter = String.Format("(sAMAccountName={0})", Username)
            result = oSearcher.FindOne
            If Not result Is Nothing Then
                Dim user As New DirectoryEntry(result.Path, LDAPUser, LDAPPass, DirectoryServices.AuthenticationTypes.Secure)
                'Disable the Account
                user.Properties("userAccountControl").Value = 514
                'Move to the New Disabled OU
                user.MoveTo(New DirectoryEntry(DisabledOu, LDAPUser, LDAPPass, DirectoryServices.AuthenticationTypes.Secure))
                Return True
                Return False
            End If
        End Function








    Monday, September 16, 2013 10:11 AM