Edit Multiple Users Object TerminalServicesHomeDir

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 14 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
saravanan.kumar
Posts: 6
Last visit: Tue Sep 22, 2009 11:28 pm

Edit Multiple Users Object TerminalServicesHomeDir

Post by saravanan.kumar »

Hi All,

Please find the script to Edit Multiple Users Object TerminalServicesHomeDirectory path from a Input file Users.txt (contains AD accounts)which reads the file line by line and you will receive the status of accounts edited in the screen and also a log file where you have copied the AD_User_Edit_V2.vbs file.

Please let me know for any futher ehnancement for the script
----------------------------------------------------------------------------------------------
'==========================================================================' NAME: <AD_User_Edit_V2.vbs>' AUTHOR: Saravanan Kumar' DATE : 8/11/2009' COMMENT: Edit Multiple Users Object details in Active Directory'==========================================================================On Error Resume NextDim objFSO, objFileconst ForReading = 1Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")Set objFile = objFSO.OpenTextFile("Users.txt", 1)Set objFile1 = objFSO.CreateTextFile("Users_Status.txt", 8)
Do Until objFile.AtEndOfStreamStruser = Trim(objFile.ReadLine)UserDN = SearchDistinguishedName(Struser)
'--------------------------------------------------------------------------' Edit the Information required
'TSHomeDrive = "<Server name><Sharename>" & Struser'TSProfile = "<Server name><Sharename>" & StruseTSHomeDirectory = "<Server name><Sharename>" & Struse'--------------------------------------------------------------------------Set ObjUser = GetObject("LDAP://" & UserDN)
If Err.Number = 0 Then 'objUser.TerminalServicesHomeDrive = TSHomeDrive 'objUser.TerminalServicesProfilePath = TSProfile objUser.TerminalServicesHomeDirectory = TSHomeDirectory ObjUser.SetInfo Wscript.Echo "Modified the TerminalServicesHomeDirectory to - " & TSHomeDirectory & " for User :- " & Struser objFile1.Write "Modified the TerminalServicesHomeDirectory to - " & TSHomeDirectory & " for User :- " & Struser & Vbcrlf
ElseIf Err.Number = -2147022676 Then Wscript.Echo "The Account does not exist in the domain : " & Struser objFile1.Write "The Account does not exist in the domain : " & Struser & VbcrlfElse Wscript.Echo "The Account status could not be determined for : " & Struser objFile1.Write "The Account status could not be determined for : " & Struser & VbcrlfEnd IfLoop
Public Function SearchDistinguishedName(ByVal vSAN) ' Function: SearchDistinguishedName ' Description: Searches the DistinguishedName for a given SamAccountName ' Parameters: ByVal vSAN - The SamAccountName to search ' Returns: The DistinguishedName Name Dim oRootDSE, oConnection, oCommand, oRecordSet
Set oRootDSE = GetObject("LDAP://rootDSE") Set oConnection = CreateObject("ADODB.Connection") oConnection.Open "Provider=ADsDSOObject;" Set oCommand = CreateObject("ADODB.Command") oCommand.ActiveConnection = oConnection oCommand.CommandText = "<LDAP://" & oRootDSE.get("defaultNamingContext") & _ ">;(&(objectCategory=User)(samAccountName=" & vSAN & "));distinguishedName;subtree" Set oRecordSet = oCommand.Execute On Error Resume Next SearchDistinguishedName = oRecordSet.Fields("DistinguishedName") On Error GoTo 0 oConnection.Close Set oRecordSet = Nothing Set oCommand = Nothing Set oConnection = Nothing Set oRootDSE = NothingEnd Function
User avatar
saravanan.kumar
Posts: 6
Last visit: Tue Sep 22, 2009 11:28 pm

Edit Multiple Users Object TerminalServicesHomeDir

Post by saravanan.kumar »

Hi All,

Please find the script to Edit Multiple Users Object TerminalServicesHomeDirectory path from a Input file Users.txt (contains AD accounts)which reads the file line by line and you will receive the status of accounts edited in the screen and also a log file where you have copied the AD_User_Edit_V2.vbs file.

Please let me know for any futher ehnancement for the script
----------------------------------------------------------------------------------------------
'==========================================================================' NAME: <AD_User_Edit_V2.vbs>' AUTHOR: Saravanan Kumar' DATE : 8/11/2009' COMMENT: Edit Multiple Users Object details in Active Directory'==========================================================================On Error Resume NextDim objFSO, objFileconst ForReading = 1Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")Set objFile = objFSO.OpenTextFile("Users.txt", 1)Set objFile1 = objFSO.CreateTextFile("Users_Status.txt", 8)
Do Until objFile.AtEndOfStreamStruser = Trim(objFile.ReadLine)UserDN = SearchDistinguishedName(Struser)
'--------------------------------------------------------------------------' Edit the Information required
'TSHomeDrive = "<Server name><Sharename>" & Struser'TSProfile = "<Server name><Sharename>" & StruseTSHomeDirectory = "<Server name><Sharename>" & Struse'--------------------------------------------------------------------------Set ObjUser = GetObject("LDAP://" & UserDN)
If Err.Number = 0 Then 'objUser.TerminalServicesHomeDrive = TSHomeDrive 'objUser.TerminalServicesProfilePath = TSProfile objUser.TerminalServicesHomeDirectory = TSHomeDirectory ObjUser.SetInfo Wscript.Echo "Modified the TerminalServicesHomeDirectory to - " & TSHomeDirectory & " for User :- " & Struser objFile1.Write "Modified the TerminalServicesHomeDirectory to - " & TSHomeDirectory & " for User :- " & Struser & Vbcrlf
ElseIf Err.Number = -2147022676 Then Wscript.Echo "The Account does not exist in the domain : " & Struser objFile1.Write "The Account does not exist in the domain : " & Struser & VbcrlfElse Wscript.Echo "The Account status could not be determined for : " & Struser objFile1.Write "The Account status could not be determined for : " & Struser & VbcrlfEnd IfLoop
Public Function SearchDistinguishedName(ByVal vSAN) ' Function: SearchDistinguishedName ' Description: Searches the DistinguishedName for a given SamAccountName ' Parameters: ByVal vSAN - The SamAccountName to search ' Returns: The DistinguishedName Name Dim oRootDSE, oConnection, oCommand, oRecordSet
Set oRootDSE = GetObject("LDAP://rootDSE") Set oConnection = CreateObject("ADODB.Connection") oConnection.Open "Provider=ADsDSOObject;" Set oCommand = CreateObject("ADODB.Command") oCommand.ActiveConnection = oConnection oCommand.CommandText = "<LDAP://" & oRootDSE.get("defaultNamingContext") & _ ">;(&(objectCategory=User)(samAccountName=" & vSAN & "));distinguishedName;subtree" Set oRecordSet = oCommand.Execute On Error Resume Next SearchDistinguishedName = oRecordSet.Fields("DistinguishedName") On Error GoTo 0 oConnection.Close Set oRecordSet = Nothing Set oCommand = Nothing Set oConnection = Nothing Set oRootDSE = NothingEnd Function
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Edit Multiple Users Object TerminalServicesHomeDir

Post by jvierra »

Here is a much easier way to get the DN for a user knowing the account name. It is faster and direct.

Code: Select all

	
msgBox GetDN( "SEC", "jvierra" )
	
Function GetDN( domain, samAccount )  
    ' Use ADSI to translate SAM account name to DN
    Set NT= CreateObject("NameTranslate") 
    NT.Init 3, "" 
    NT.Set 3, domain & "" & samAccount
    GetDN = NT.Get(1)
End Function
	

jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Edit Multiple Users Object TerminalServicesHomeDir

Post by jvierra »

ADSI TranslateName is much faster and also much easier to remember so we can just type it into a script once you see how it works.
Ras - look at your script. It has a few mistakes/typos.
User avatar
rasimmer
Posts: 182
Last visit: Fri Apr 25, 2014 7:00 am

Edit Multiple Users Object TerminalServicesHomeDir

Post by rasimmer »

Mistakes...my script...pshhh...

errr...Ok...I think I fixed em'
This topic is 14 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked