Script to Set Users TSprofile path location in AD
User names should be seperated by a carriage return inside users.txt
I used this script during a migration of users to a hybrid profile solution. I did not want to set the path with GPO as i wanted a controlled migration over a period of time. Once the migration was completed the path was however controlled via GPO.
' Set User TSProfile path.vbs
'
' Sets users in users.txt to TS profile path C:\Mandatory_Profile
'
'
'
Dim objConnection, objCommand, objRootDSE, strDNSDomain
Dim strFilter, strQuery, objRecordSet, objArgs, usr
StrTSProfile = "c:\Mandatory_Profile"
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set objInputFile = objFileSystem.OpenTextFile("users.txt",1)
inputData = Split(objInputFile.ReadAll, vbNewline)
For Each StrData in inputdata
Sam = StrData
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOOBject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "
strFilter = "(&(objectCategory=person)(objectClass=user)(sAMAccountName=" & sam & "))"
strAttributes = "distinguishedName,sAMAccountName"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 99999
objCommand.Properties("Timeout") = 300
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strDN = objRecordSet.Fields("distinguishedName")
objRecordSet.MoveNext
Loop
objConnection.Close
Set objConnection = Nothing
Set objCommand = Nothing
Set objRootDSE = Nothing
Set objRecordSet = Nothing
Set Objuser = Getobject ("LDAP://" & strDN & "")
StrPath = objUser.TerminalServicesProfilePath
objUser.TerminalServicesProfilePath = StrTSProfile
objuser.setinfo
Next
objInputFile.Close
WScript.Echo "Completed"
wscript.quit
Labels: Scripts
0 Comments:
Post a Comment
<< Home