Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ScriptingPro/de4c9e0eb491c5d1c890f3dad154cb7f to your computer and use it in GitHub Desktop.
Save ScriptingPro/de4c9e0eb491c5d1c890f3dad154cb7f to your computer and use it in GitHub Desktop.
PowerShell Set Terminal Services Profile Path
<#
Set Active Directory Users Terminal Services Profile Path Using PowerShell
There is no remote desktop services profile path attribute, because TerminalServicesProfilePath is saved in the Active Directory user object's UserParameters attribute as a binary blob
This snippet will find ADUsers that match $TSProfilePath_OLD and set their remote desktop services profile path to $TSProfilePath_NEW
#>
# Need Active Directory Cmdlets
Import-Module ActiveDirectory
# Change TerminalServicesProfilePath only on users that are currently pointing to:
$TSProfilePath_OLD = '\\aserverthatdoesnotexist\fake_share$\whatever.man'
# New TerminalServicesProfilePath
$TSProfilePath_NEW = '\\newaserverthatdoesnotexist\newfake_share$\newwhatever.man'
# Find Them
$UsersToBeModified = Get-ADUser -filter * | select samaccountname, DistinguishedName, @{n="TSProfilePath";e={([adsi]("LDAP://" + $_.DistinguishedName)).psbase.InvokeGet("terminalservicesprofilepath")}} | ?{$_.TSProfilePath -eq $TSProfilePath_OLD}
#Modify Them
foreach($UserToBeModified in $UsersToBeModified){
Write-Host ("Working on " + $UserToBeModified.samaccountname)
$DirectoryEntry = [adsi]("LDAP://" + $UserToBeModified.DistinguishedName)
$DirectoryEntry.psbase.invokeSet("TerminalServicesProfilePath",$TSProfilePath_NEW)
$DirectoryEntry.setinfo()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment