08 Jul 10 09 - Powershell - TS Home Directory

nordtorp
nordtorp used Ask the Experts™
on
Sirs,

I have a rare problem.

Background:
I have set the TSHomeDrive and TSHomeDirectory property of a user at a Windows Server 2008 through PowerShell (v2.0).
I use Quest ActiveRoles Management Shell cmdlets to make these changes. This is the command I run:

Set-QADUser $id -TsHomeDrive "H" -TsHomeDirectory $TSHome

Problem:
When I try to login to a TS with this user the home drive is not mapped.

Workaround:
Open the user AD object and set TSHomeDirectory to Local Path, then set it back to Connect. Log back in.

I am looking for a way to get this to work by just setting these settiings in PowerShell. The domain functional level is 2003, but the command ran from a 2008 AD controller (still 2003 functional level)

Please ask for more details relevant to this if you feel I left something out.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I dont know if powershell is a must for this but I have done this is the past quite easily using admodify. This tool will let you select any of your users either by ou, name, ldap query,etc and then set any attribute youd like for them.

To enable the terminal services tab you need to run this tool from a server 2003 or higher computer.

Download here
http://admodify.codeplex.com/


1.jpg

Author

Commented:
xxdcmast,

Thank you for the response, but I would like to know why this happen.

Does 2003 and 2008 read the values differently? I have read the values through PowerShell, but it seems to be the exact thing.
Commented:
Try with this script. I used it many times. It works with users defined in "usersTS.txt" file but you can easily moidfy it.
add-pssnapin Quest.ActiveRoles.ADManagement
$UsersCSVFile='.\usersTS.txt'
$TSProfile='\\tsprofile\profile$\'
$TSData='\\tsprofile\data$\'
$DNSRoot=(Connect-QADService).Domain.Name; 
Write-Host 'Running on domain', $DNSRoot
$UsersList = Import-Csv $UsersCSVFile
$UsersList = $UsersList | Where-Object {$_.username -ne ''}

If (($UsersList | Measure-Object).Count -eq 0) {
                Write-Host 'Error importing',$UsersCSVFile,'file!'; 
                Break
                }

foreach ($UserToChange in  $UsersList ) {
                $UserName=$UserToChange.username
                if ($UserName -eq $null) {
                                Continue;
                                }
                Write-Host $UserName, '... ' -NoNewLine
                $TSUser=(Get-QADUser $UserName)
                $TSUser.TSProfilePath=$TSProfile+$UserName
                $TSUser.TsHomeDirectory=$TSData+$UserName
                $TSUser.TSHomeDrive='Z:'
                $TSUser.CommitChanges()
                Write-Host 'OK.' 
                }
Write-Host
Write-Host 'Done!'
Write-Host

Open in new window

Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

Commented:
One additional info if you missed it: my script reads CSV file so the first line should contain "username" word and next lines should contain real user names in AD.

Author

Commented:
Thank you for the answer gtworek.

Please see my code below. I will show what I tried earlier on and what changes I made corresponding to your example.

AND IT WORKED :D

You will get full points for this, but the million dollar question is, why did it work?
Before:
    $quser = get-qaduser $user
    $TSHome = '\\server\private$\$user'

    $quser.TsHomeDrive = 'H:'
    $quser.TsHomeDirectory = $TShome 
    $quser.CommitChanges()

Now:
    $quser = (get-qaduser $user)    
    $TSHome = '\\server\private$\'

    $quser.TsHomeDrive = 'H:'
    $quser.TsHomeDirectory = $TShome+$user 
    $quser.CommitChanges()

Open in new window

Commented:
I have no idea :)
And no possibility to check now. But I suggest you to test your old script step by step and look into your variables including Get-Members cmdlet.

Author

Commented:
Thank you for your answer, I have been trying a lot of things, and the solution were just in front of my nose.

Thanks again!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial