2
votes

I'm using a PowerShell script I found to add new AD users. It reads info from a CSV file, and everything works well, except that I need it to set the initial startup program for the new users. Here is the command:

New-ADUser $sam -GivenName $_.GivenName -DisplayName $_.DisplayName `
-UserPrincipalName ($sam + "@" + $dnsroot) -AccountPassword $setpass -Enabled $enabled `
-PasswordNeverExpires $expires -OtherAttributes @{'msTSInitialProgram'="programToRun"; 'msTSWorkDirectory'="directoryToRunIn"}

After looking at the user that is created, I see that it effectively ignores the -OtherAttributes. Am I missing an attribute somewhere that is causing it to skip setting the initial program?

1
What is the version of you server ? - JPBlanc
It's Server 2008 R2. I assumed that the msTSInitialProgram and msTSWorkDirectory attributes would set the the values on the environment tab, but I guess that assumption was wrong. - Travieso
Asked a new question that's more relevant to what I'm looking for - How can I set the values on the Environment tab using New-ADUser - Travieso

1 Answers

0
votes

The 'msTSInitialProgram' attribute specifies the path and file name of the application that the user wants to start automatically when the user logs on to the terminal server. To set an initial application to start when the user logs on, the implementer must first set this property, and then set the TerminalServicesWorkDirectory property. If the implementer sets only the TerminalServicesInitialProgram property, the application starts in the user's session in the default user directory.

These attributes are implemented on Windows Server 2008 operating system, Windows Server 2008 R2 operating system, Windows Server 2012 operating system, and Windows Server 2012 R2 operating system.

On my Windows Server 2012 your command line works, run as administrator, works perfectly and assigned 'msTSInitialProgram' and 'msTSWorkDirectory' as you can see here under.

New-ADUser "T2" -GivenName "Tg" -DisplayName "T2" `
-UserPrincipalName ("[email protected]") -Enabled $true -AccountPassword $(convertto-securestring "P@ssW0rD!" -asplaintext -force) `
-OtherAttributes @{'msTSInitialProgram'="programToRun"; 'msTSWorkDirectory'="directoryToRunIn"}

enter image description here