{"id":303,"date":"2018-07-23T15:42:53","date_gmt":"2018-07-23T14:42:53","guid":{"rendered":"https:\/\/blog.van-daag.nl\/?p=303"},"modified":"2018-07-23T15:42:53","modified_gmt":"2018-07-23T14:42:53","slug":"ad-change-roaming-profile-path-terminal-server","status":"publish","type":"post","link":"https:\/\/van-daag.nl\/?p=303","title":{"rendered":"AD Change Roaming profile Path Terminal server"},"content":{"rendered":"<p>I created this script because of moving the profiles to a server in the data center were also the terminal server is located.<\/p>\n<p>Powershell needs to be runned as Administrator<\/p>\n<pre class=\"lang:ps decode:true\" title=\"Change_Profile.ps1\">########\r\n## created by Daag van der Meer\r\n## blog.van-daag.nl\r\n## 26-04-2018\r\n########\r\n#\r\n# Script is used to set Homedrive, RDP Homedrive, Profilepath, RDP profile path.\r\n#\r\n# Script needs to be runned as Admin!!!\r\n\r\n\r\nImport-Module ActiveDirectory\r\n     # On the Domain Controller There is on C:\\Temp\\Users.txt with the usernames to change the path\r\n\r\nforeach ($user in (get-content c:\\temp\\Users.txt)) {\r\n    ## Homedrive and profile location\r\n    $homeDirectory = '\\\\&lt;NewServer&gt;\\home$\\&lt;Country&gt;\\' + $user; \r\n    $ProfilePath = '\\\\&lt;NewServer&gt;\\Profile$\\&lt;Country&gt;\\' + $user; \r\n\r\n    ## Set homedrive (DISABLE THIS IF YOU DON'T WANT TO CHANGE THIS)\r\n    # Finally set their home directory and home drive letter in Active Directory\r\n    Set-ADUser -Identity $user -HomeDirectory $homeDirectory -HomeDrive H\r\n\t\r\n\t## Set Profile (DISABLE THIS IF YOU DON'T WANT TO CHANGE THIS)\r\n\t\tSet-ADUser -Identity $user -ProfilePath $ProfilePath\r\n        \r\n        ## Set RDP Profile and Homedrive\r\n        Get-ADUser -Filter \"SAMAccountName -like '$user*'\"| ForEach-Object {\r\n        $ADSI = [ADSI]('LDAP:\/\/{0}' -f $_.DistinguishedName)\r\n        try {\r\n            $ADSI.InvokeSet('TerminalServicesProfilePath',$ProfilePath)\r\n            $ADSI.InvokeSet(\"TerminalServicesHomeDrive\",\"H:\")\r\n            $ADSI.InvokeSet(\"TerminalServicesHomeDirectory\",$homeDirectory)\r\n            $ADSI.SetInfo()\r\n        }\r\n        catch {\r\n            Write-Error $Error[0]\r\n        }\r\n}\r\n\t\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I created this script because of moving the profiles to a server in the data center were also the terminal server is located. Powershell needs to be runned as Administrator ######## ## created by Daag van der Meer ## blog.van-daag.nl ## 26-04-2018 ######## # # Script is used to set Homedrive, RDP Homedrive, Profilepath, RDP [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[6,11,21],"tags":[],"class_list":["post-303","post","type-post","status-publish","format-standard","hentry","category-microsoft","category-powershell-script","category-windows-server-2012r2"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/van-daag.nl\/index.php?rest_route=\/wp\/v2\/posts\/303","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/van-daag.nl\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/van-daag.nl\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/van-daag.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/van-daag.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=303"}],"version-history":[{"count":1,"href":"https:\/\/van-daag.nl\/index.php?rest_route=\/wp\/v2\/posts\/303\/revisions"}],"predecessor-version":[{"id":304,"href":"https:\/\/van-daag.nl\/index.php?rest_route=\/wp\/v2\/posts\/303\/revisions\/304"}],"wp:attachment":[{"href":"https:\/\/van-daag.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/van-daag.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/van-daag.nl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}