【问题标题】:How can I set the values on the Environment tab using New-ADUser with PowerShell?如何使用带有 PowerShell 的 New-ADUser 设置环境选项卡上的值?
【发布时间】:2025-12-09 00:00:02
【问题描述】:

我正在使用 PowerShell 脚本从 CSV 文件添加用户,但我一直无法找到在“环境”选项卡上设置值的方法。我试过使用

-OtherAttributes @{'msTSInitialProgram'="programToRun"; 'msTSWorkDirectory'="directoryToRunIn"}

无济于事。 我正在使用服务器 2008 R2。这是我正在谈论的标签:

如何设置这些值?

【问题讨论】:

    标签: powershell active-directory


    【解决方案1】:

    如果其他人有兴趣:

    $dn  = (Get-ADUser $user).DistinguishedName 
    $ext = [ADSI]"LDAP://$dn" 
    $ext.PSBase.InvokeSet("TerminalServicesInitialProgram","C:\Temp\test.bat")
    $ext.PSBase.InvokeSet("TerminalServicesWorkDirectory","C:\Temp\TestingToTheBone")
    $ext.SetInfo()
    

    在此选项卡上设置值。

    http://gallery.technet.microsoft.com/scriptcenter/PowerShell-Create-Active-7e6a3978/view/Discussions

    【讨论】:

      最近更新 更多