Home > Powershell, Windows Server 2003 / 2008 > Powershell: Clear TsProfilePath in Active Directory

Powershell: Clear TsProfilePath in Active Directory

Last week I had an odd issue in powershell when I was creating a script to clear the “Terminal Services profile” for a list of users. The following error appeard when I tried to clear the Terminal services path via “Get-QADUser test_user | Set-QADUser -TsProfilePath $null”:

Set-QADUser : The specified directory service attribute or value does not exist. (Exception from HRESULT: 0x8007200A)

After a little reaserach I found a topic on Powergui with similar problems. It turns out that there might be a problem between ADSI and powershell for the “Terminal Services profile” settings when you try to clear these settings.  Fortunly a member of the Powergui made already a workaround with ADSI and PSBase.

Add or remove the following lines in the underneath script to clear the HomeDrive, HomeDirectory and the Profilepath.

$objADSI.psbase.InvokeSet(“TerminalServicesHomeDrive”, “”)
$objADSI.psbase.InvokeSet(“TerminalServicesHomeDirectory”, “”)
$objADSI.psbase.InvokeSet(“TerminalServicesProfilePath”, “”)

This example clears the “Terminal services profile path” for the samaccountname column in accounts.csv :

#This script will clear the Terminal Services Profile Path based on a csv file

$imported = Import-Csv "C:\Input\Accounts.csv"

$imported | ForEach-Object {
get-qaduser $_.Samaccountname | Modify-DirectoryObject

function Modify-DirectoryObject {
begin {$count=0}
process {
$objADSI = [ADSI]$_.Path
$objADSI.psbase.InvokeSet("TerminalServicesProfilePath", "")
end {"objects were modified"}


  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: