Announcement

Collapse
No announcement yet.

Loop through Active Directory Users and search for one configured with terminalprofil

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Loop through Active Directory Users and search for one configured with terminalprofil

    Need help to come up with a script which loops thorugh Active Directory and find the user account which are configured with terminal server profile and delete the terminal server profile path. I found the sample script below , how can I modify the script to loop through all users in OU and set path =blank?


    Set objUser = GetObject _
    ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")
    objUser.Put "profilePath", "\\sea-dc-01\Profiles\myerken"
    objUser.SetInfo

  • #2
    Re: Loop through Active Directory Users and search for one configured with terminalpr

    Try this:

    Code:
    'OU's to query (change this for the OU you want to query)
    Fix "China"
    
    Sub Fix(sOU)
    
     Set objRootDSE = GetObject("LDAP://rootDSE")
     strDNSDomain = objRootDSE.Get("defaultNamingContext")
    
     'Start the ADO connection
     Set objCommand = CreateObject("ADODB.Command")
     Set objConnection = CreateObject("ADODB.Connection")
     objConnection.Provider = "ADsDSOObject"
     objConnection.Open "Active Directory Provider"
     objCommand.ActiveConnection = objConnection
    
     'Set the ADO connection query strings
     StartNode = strDNSDomain
     SearchScope = "subtree"
    
     'find all enabled users using bitmask attributes
     FilterString = "(&(objectCategory=person)(objectClass=user)" _
                 	   & "(userAccountControl:1.2.840.113556.1.4.803:=2))"
     Attributes = "adspath"
    
     'Create the LDAP-Query
     LDAPQuery = "<LDAP://OU=" & sOU & "," & StartNode & ">;" & FilterString & ";" _
                	& Attributes & ";" & SearchScope
    
     objCommand.CommandText = LDAPQuery
     objCommand.Properties("Page Size") = 100
     objCommand.Properties("Timeout") = 30
     objCommand.Properties("Cache Results") = False
    
     Set objRecordSet = objCommand.Execute
    
     If NOT objRecordSet.eof Then
      objRecordSet.MoveFirst
      While Not objRecordset.EOF
        Set objUser = GetObject(objRecordSet.Fields("AdsPath").Value)
    
            ' set the terminal sever profile path to nothing
           objUser.TerminalServicesProfilePath = ""
    	objUser.SetInfo 
    
        Set objUser = Nothing
        objRecordSet.MoveNext
      Wend
     End If
    End Sub
    
    msgbox "Done!"
    WScript.Quit
    Last edited by ekrengel; 26th May 2009, 22:27.

    Comment


    • #3
      Re: Loop through Active Directory Users and search for one configured with terminalpr

      objUser.Put "profilePath" is for terminal server profile or roaming profile?

      Comment


      • #4
        Re: Loop through Active Directory Users and search for one configured with terminalpr

        Oh sorry yes that is correct. I assumed your first post was what you tested on removing the terminal server profile path. What you are looking for is the ""CtxWFProfilePath" userParameter. See HERE and scroll down to the section that has the picture for the Terminal Services Profile Tab. The ADS attribute name for this is "TerminalServicesProfilePath"

        I made an edit to the first post with the updated script.

        Comment


        • #5
          Re: Loop through Active Directory Users and search for one configured with terminalpr

          Thanks for your help ekrengel!

          What is the diff between your script and the script I was trying? How can I make my script loop through all users in management OU?

          Set objUser = GetObject _
          ("LDAP://ou=management,dc=fabrikam,dc=com")
          objUser.Put "profilePath", "\\sea-dc-01\Profiles\myerken"
          objUser.SetInfo

          Comment


          • #6
            Re: Loop through Active Directory Users and search for one configured with terminalpr

            Originally posted by bhavin78 View Post
            Thanks for your help ekrengel!

            What is the diff between your script and the script I was trying? How can I make my script loop through all users in management OU?

            Set objUser = GetObject _
            ("LDAP://ou=management,dc=fabrikam,dc=com")
            objUser.Put "profilePath", "\\sea-dc-01\Profiles\myerken"
            objUser.SetInfo

            Well from what you just pasted, you would only be running the script against one user. You actually aren't specifying any user object, so that would error out. You would have to change "LDAP://ou=management,dc=fabrikam,dc=com" TO "LDAP://cn=username,ou=management,dc=fabrikam,dc=com"

            Now the real difference between my script and yours, is that by creating an objectRecordset, I can enumerate all the users in the management OU (in your case) by creating a subroutine called Fix, and remove the terminal services profile attribute in each object after they have all been populated. I suggest reading rlmueller's LDAP Binding Strings to really get a better understanding of what I am talking about.

            Also take a look at ADO Search Tips

            This should help you understand a little better, and get you involved with some more advanced scripting...just be careful

            Comment


            • #7
              Re: Loop through Active Directory Users and search for one configured with terminalpr

              Thank you, that was really helpful.

              Appreciate your time and help.

              Comment

              Working...
              X