{"id":1694,"date":"2013-04-16T19:11:44","date_gmt":"2013-04-16T19:11:44","guid":{"rendered":"http:\/\/www.obieta.com\/?p=1694"},"modified":"2013-04-16T19:11:44","modified_gmt":"2013-04-16T19:11:44","slug":"vbscript-to-change-location-of-ous-users-home-folders","status":"publish","type":"post","link":"https:\/\/obieta.com\/?p=1694","title":{"rendered":"VBscript to change location of OU&#8217;s users home folders"},"content":{"rendered":"<p>Terminal Service profile is not an AD attribute<br \/>WARNING: Not an Active Directory attribute Terminal Services Attributes are accessed via the IADsTSUserEx interface. \u00a0You may receive an &#8220;Object doesn&#8217;t support this property or method&#8221; error when you try to run the code. \u00a0This error will probably indicate that you don&#8217;t have the &#8220;TsUserEx.dll&#8221; file is required to run this code.<\/p>\n<pre><code id=\"questionCommentsViewCode20-20429188-9423\">'=================\nOption Explicit\n\nDim adoCommand, adoConnection, strBase, strFilter, strAttributes\nDim objRootDSE, strDNSDomain, strQuery, adoRecordset, strDN , strOUPath\nDim objUser\n\nConst ADS_PROPERTY_CLEAR = 1\n\n' Setup ADO objects.\nSet adoCommand = CreateObject(\"ADODB.Command\")\nSet adoConnection = CreateObject(\"ADODB.Connection\")\nadoConnection.Provider = \"ADsDSOObject\"\nadoConnection.Open \"Active Directory Provider\"\nadoCommand.ActiveConnection = adoConnection\n\nstrOUpath = \"OU=test,\"\n\n' Search entire Active Directory domain.\nSet objRootDSE = GetObject(\"LDAP:\/\/RootDSE\")\nstrDNSDomain = objRootDSE.Get(\"defaultNamingContext\")\nstrBase = \"&lt;LDAP:\/\/\" &amp; stroupath &amp; strDNSDomain &amp; \"&gt;\"\n\n' Filter on user objects with a value assigned to scriptPath.\nstrFilter = \"(&amp;(objectCategory=person)(objectClass=user))\"\n\n' Comma delimited list of attribute values to retrieve.\nstrAttributes = \"distinguishedName\"\n\n' Construct the LDAP syntax query.\nstrQuery = strBase &amp; \";\" &amp; strFilter &amp; \";\" &amp; strAttributes &amp; \";subtree\"\nadoCommand.CommandText = strQuery\nadoCommand.Properties(\"Page Size\") = 100\nadoCommand.Properties(\"Timeout\") = 30\nadoCommand.Properties(\"Cache Results\") = False\n\n' Run the query.\nSet adoRecordset = adoCommand.Execute\n\n' Enumerate the resulting recordset.\nDo Until adoRecordset.EOF\n\n    ' Retrieve values.\n    strDN = adoRecordset.Fields(\"distinguishedName\").Value\n\n    ' Bind to user object.\n    Set objUser = GetObject(\"LDAP:\/\/\" &amp; strDN)\n\nWScript.Echo objUser.Name, objUser.AllowLogon\n\n    ' Clear the allowlogon attribute.\n      objUser.TerminalServicesProfilePath = \"\\Servershare\"\n      objuser.scriptPath = \"loginscript.bat\"\n      objUser.setinfo\n\n    ' Save changes.\n    'objUser.SetInfo\n\nWScript.Echo objUser.Name\n    ' Move to the next record in the recordset.\n    adoRecordset.MoveNext\nLoop\n\n' Clean up.\nadoRecordset.Close\n\nadoConnection.Close\n'============ <\/code><\/pre>\n<div><code>objUser.Put \"homeDirectory\", \"\\hu.lcldfsuser&lt;username&gt;\"<br \/>objUser.Put \"homeDrive\", \"U:\"<br \/><\/code><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Terminal Service profile is not an AD attributeWARNING: Not an Active Directory attribute Terminal Services Attributes are accessed via the IADsTSUserEx interface. \u00a0You may receive an &#8220;Object doesn&#8217;t support this property or method&#8221; error when you try to run the code. \u00a0This error will probably indicate that you don&#8217;t have the &#8220;TsUserEx.dll&#8221; file is required [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1,8],"tags":[],"_links":{"self":[{"href":"https:\/\/obieta.com\/index.php?rest_route=\/wp\/v2\/posts\/1694"}],"collection":[{"href":"https:\/\/obieta.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/obieta.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/obieta.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/obieta.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1694"}],"version-history":[{"count":0,"href":"https:\/\/obieta.com\/index.php?rest_route=\/wp\/v2\/posts\/1694\/revisions"}],"wp:attachment":[{"href":"https:\/\/obieta.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1694"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/obieta.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1694"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/obieta.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1694"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}