Terminal Server Profile Path Woes
During a migration process I came accross this odd problem.
I could not change a Terminal Server Profile Path for a couple of hundred users.
I searched the microsoft site but I could not find anything that would help me quick.
Yes I did find this link http://technet.microsoft.com/en-us/library/cc783578.aspx
But my client did not have grouppolicies in place and I did not want to use the "Terminal Services Extension"
I found several partly usefull scripts I combined the best of them in the script below. I really hope you will find this usefull.
I could not change a Terminal Server Profile Path for a couple of hundred users.
I searched the microsoft site but I could not find anything that would help me quick.
Yes I did find this link http://technet.microsoft.com/en-us/library/cc783578.aspx
But my client did not have grouppolicies in place and I did not want to use the "Terminal Services Extension"
I found several partly usefull scripts I combined the best of them in the script below. I really hope you will find this usefull.
'******************************************************************************
Const ADS_SCOPE_SUBTREE = 2
Const ForAppending = 8
On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("c:\myusers.txt", ForAppending, True)
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection
'Change the below LDAP query to select the users in your correct OU
objCommand.CommandText = "Select sAMAccountName,name from 'LDAP://OU=Users,OU=_GlobalResources,OU=e178,DC=emea,DC=corpdir,DC=net' " & "Where objectClass='user'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
objTextFile.WriteLine(objRecordSet.Fields("sAMAccountName").Value)
objRecordSet.MoveNext
Loop
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\myusers.txt", 1, True)
Set objTextFile2 = objFSO.OpenTextFile("c:\myresults.txt", 8, True)
Dim arrUsers()
i = 0
Do Until objTextFile.AtEndOfStream
Redim Preserve arrUsers(i)
arrUsers(i) = objTextFile.ReadLine
i = i + 1
Loop
objTextFile.Close
For Each myUser in arrUsers
'in de my user file staan samAccounts hiermee kan je ldap niet bevragen dit zou via ado moeten.
'er is echter een methode om een samAccount om te zetten in een DN.
Dim objUser
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
strNetBIOSDomain = "your_netbios_domain_name" ' <-- change this
strNTName = myUser
Set objTrans = CreateObject("NameTranslate")
objTrans.Init ADS_NAME_INITTYPE_GC, ""
objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strNTName
strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
strUserDN = Replace(strUserDN, "/", "\/")
Set objUser = GetObject("LDAP://" & strUserDN)
strTSPath = objUser.TerminalServicesProfilePath
strOudeServer = "old_server_name" '<-- change this
strNieuweServer = "new_server_name" '<-- change this
strTSPath_new = Replace(strTSPath,strOudeServer,strNieuweServer)
If Mid(strTSPath,3,8) = strOudeServer Then
'Display some logging
objTextFile2.WriteLine(myUser)
objTextFile2.WriteLine("Terminal Server Profile Path OLD: " & objUser.TerminalServicesProfilePath)
objTextFile2.WriteLine("Terminal Server Profile Path NEW: " & strTSPath_new)
'### The Actual change takes place here.
objUser.TerminalServicesProfilePath = strTSPath_new
objUser.setinfo
'####################################################################
End If
Next
objTextFile2.Close
'******************************************************************************
Comments
thanks
vipin