Remove RDS profile path & home folder for bulk users P shell

How to remove profile path, RDS Profile path and RDS Home folder from PowerShell.

This article will help on bulk action for AD users properties, especially for removing the Terminal Service or Remote Desktop Services profile path, home folder and profile path by using PowerShell script with import function in script and get the list of users from csv files and script for get users from a specific OU and take action on that.

Will remove below attributes from AD users properties: -
Profile tab: – ProfilePath and HomeFolder (HomeDirectory)
Remote Desktop Service Profile Tab: - Profile Path and Home Folder

Script for removing attribute from Profile Tab:-Script for removing attribute from Profile Tab:-
Here ProfilePath and connect to (Homedirectory) are standard attribute for using in AD PowerShell module, so we are using it.
Copy the below code and paste in .txt file and save as filename.ps1 then you can run this script, or 
download hereRemove-ProfilePath-HomeDirectory.ps1
Replace “C:\temp\users.txt” with your user list file.

Script for removing attribute from RDS Profile using Import-CSV: -
Below script will help to remove Profile path and Home folder from Remote desktop profile tab of AD user properties. In this script just need to change the file path of users list by replacing the C:\temp\accounts.csv with your csv file. Please create the .csv file in the below format. Click here to download the script - Remove-RDS-ProfilePath-homeFolder-From-OU.Ps1

# Set TSProfile Path for users which are listed in .csv file in following format# Set TSProfile Path for users which are listed in .csv file in following format
# samaccountname
# testuser
$imported = Import-Csv "C:\temp\accounts.csv"
Foreach ($user in $imported) {
$AD = get-aduser $user.samaccountname | select -ExpandProperty disting*
$ADUser = [ADSI]“LDAP://$AD”
$ADUser.psbase.InvokeSet(“terminalservicesprofilepath”,"")
$ADUser.psbase.InvokeSet(“TerminalServicesHomeDirectory”,"")
$ADuser.setinfo()
}

Script for removing attribute from RDS Profile from a specific OU: -
Below script will help to remove Profile path and Home folder from Remote desktop profile tab of AD user properties. In this script just need to change the OU path by replacing the ou=test,dc=testdomain,dc=local with your OU path from where you want to remove the same from all users of OU. Click here to download this script - Remove-RDS-ProfilePath-homeFolder.Ps1

$TShdValue = ""$TShdValue = ""
$TSppValue = ""
$ObjFilter = "(&(objectCategory=person)(objectCategory=User))"
$objSearch = New-Object System.DirectoryServices.DirectorySearcher
$objSearch.PageSize = 15000
$objSearch.Filter = $ObjFilter  
$objSearch.SearchRoot = "LDAP://ou=test,dc=testdomain,dc=local"
$AllObj = $objSearch.FindAll()
foreach ($Obj in $AllObj)
{
$objItemS = $Obj.Properties
$UserDN = $objItemS.distinguishedname
$user = [ADSI] "LDAP://$userDN"
$user.psbase.invokeSet("TerminalServicesProfilePath",$TSppValue)
$user.psbase.invokeSet("TerminalServicesHomeDirectory",$TShdValue)
$user.setinfo()
}

Script for removing attribute from RDS Profile from all users, who have enabled -
Below script will help to remove Profile path and Home folder from Remote desktop profile tab of AD user properties. just save the below script as a .ps1 by using below code, Or download the readmade script by Click here to download this script - Remove-RDS-ProfilePath-homeFolderfor_all_users.Ps1

Import-Module ActiveDirectoryImport-Module
ActiveDirectoryGet-ADUser -filter * | foreach { $user = [ADSI]"LDAP://$($_.DistinguishedName)"
if ($user.TerminalServicesProfilePath -isnot [System.Management.Automation.PSMethod])
{
$user.psbase.invokeSet("TerminalServicesHomeDirectory","")
$user.psbase.invokeSet("TerminalServicesProfilePath","")  $user.setinfo() }}
$user.setinfo()$user.setinfo()
}
}