Script to remove/delete Citrix users TSP in their AD profile

Posted on 2012-08-27
Last Modified: 2012-12-12
Hello there,

I am in process of migrating Citrix Full Desktop users from old farm (XA 4.5 farm) to new XenApp 6.5 farm.

I need a script which removes/deletes Terminal Services Profile path in users AD profile.

Please advise.

Thanks and Regards
Question by:goprasad
    LVL 9

    Accepted Solution

    This little script will set the TS profile to 'strRootDir\SAMName.
    maybe its of some use, dont forget to define your server share as strRootDir and domain name in the commandtext.....

    This little script will set the TS profile to 'strRootDir\SAMName. 
    maybe its of some use, dont forget to define your server share as strRootDir and domain name in the commandtext..... 
    Set WshShell = WScript.CreateObject("WScript.Shell") 
    CurDir = WshShell.CurrentDirectory 
    ' Enter your server/share value here, don't forget the trailing strRootDir = "\\SERVER\ProfileSHARE$\" 
    SURE = MsgBox("This will modify all TS profile path ALL users" & vbcrlf & "Execute modifications?", vbYesNo, "Sure?") 
    If SURE = 6 Then 
    'Do nothing but Continue 
    Elseif SURE = 7 Then 
    End If 
    Const ADS_SCOPE_SUBTREE = 2 
    strLOGFILE = CurDir & "\chgprofTS.log" 
    strERRORLOG = CurDir & "\chgprofTS-ERROR.log" 
    Set objFSO = CreateObject("Scripting.FileSystemObject") 
    Set objLogFile = objFSO.OpenTextFile (strLOGFILE, 8, True) 
    Set objErrorLog = objFSO.OpenTextFile (strERRORLOG, 8, True) 
    Set objConnection = CreateObject("ADODB.Connection") 
    Set objCommand = CreateObject("ADODB.Command") 
    objConnection.Provider = "ADsDSOObject" 
    objConnection.Open "Active Directory Provider" 
    Set objCommand.ActiveConnection = objConnection 
    objCommand.Properties("Page Size") = 1000 
    objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
    objCommand.CommandText = _ 
    "SELECT distinguishedName, sAMAccountName FROM 'LDAP://dc=YOUR,dc=DOMAINNAME' WHERE objectCategory='user'" 
    Set objRecordSet = objCommand.Execute 
    i = 0 
    e = 0 
    strinfomsg = "Script started at " & Now 
    objLogFile.WriteLine (strinfomsg) 
    objErrorLog.WriteLine (strinfomsg) 
    Do Until objRecordSet.EOF 
    i = i + 1 
    Wscript.Echo objRecordSet.Fields("distinguishedName").Value 
    Set objUser = GetObject("LDAP://" & objRecordSet.Fields("distinguishedName")) 
    strOLD = objUser.TerminalServicesProfilePath 
    objUser.TerminalServicesProfilePath = strRootDir & objUser.samAccountName 
    if err.number 
    e = e + 1 
    objErrorLog.WriteLine (objUser.samAccountName & vbTab & err.number) 
    objLogFile.WriteLine (objUser.samAccountName & vbTab & "modified from" & vbTab & strOLD & vbTab & "to" & vbTab & objUser.TerminalServicesProfilePath) 
    End If 
    objLogFile.WriteLine (i & " modifications finished at " & Now) 
    objErrorLog.WriteLine (e & " errors occured") 
    objLogFile.WriteLine () 
    objErrorLog.WriteLine () 

    Open in new window


    Author Comment

    I just the TSP path to be deleted from the TSP tab in users AD profile, for the usernames extracted in a text file.
    LVL 5

    Assisted Solution

    LVL 32

    Expert Comment

    Is stead of mixing the two profiles up, iwould suggest making a second.GPO that will apply only when users login to your Citrix servers.

    You may also what to create a second location to store their Citrix TS profiles.

    I will post later today my gpo settins for this.

    Author Comment

    Currently users in old XA 4.5 farm has profile stored in \\xxxxxfps\Profiles$\%username% and TSP in users AD profile tab has this path
    Users when connecting to new XA 6.5 farm, Citrix Profile Management has been configured to created profile in \\xxxxxfps\CTXProfiles$\%username%

    My objective is when user A is migrated from old to new farm, I would like to have the his old TSP path removed/deleted from his AD profile.

    My plans is to migrate 50 users at a time, and I can run script to extract usernames and I want those 50 user's TSP profile path in AD to be deleted/removed.

    Please advise

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    #Citrix #XenApp #Citrix Scout #Citrix Insight Services #Microsoft VMMAP #Microsoft ADEXPLORE #Microsoft RAMMAP #Microsoft TCPVIEW #Microsoft AUTORUNS #Microsoft PROCESS EXPLORER #Microsoft PROCESS MONITOR
    Citrix XenDesktop 7.6 Citrix Policies Graphics
    This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
    This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now