在设置远程桌面服务控制权限时遇到问题?

Having trouble setting Remote Desktop Services Control permissions?

我是 power shell 的新手,我正在尝试创建一个脚本来在 Active Directory 中创建新用户。目前我在设置用户的远程桌面服务选项卡时遇到问题。我的代码如下。

#Set Remote Control Settings Permissions  
        #I recieved Server is not operational error. https://docs.microsoft.com/en-us/troubleshoot/windows-server/identity/fail-to-configure-server-using-server-manager I think Invoke Set may not be the command I should use.
        
        $userpath = dsquery user -samid $username 
        $userpat = "LDAP://$userpath"
        $userp = [ADSI]$userpat
        $userp.InvokeSet("EnableRemoteControl",2)
        $userp.setinfo()
        
        #Remote Desktop Services User profile profile path set to "\documentsf\profiles$username" THIS IS MESSING UP ERROR OCCURRS WITH INVOKE SET SAYING NOT SPECIFIED
         
        $userp.InvokeSet("terminalservicesprofilepath","\documentsf\profiles$username")
        $userp.setinfo()

远程控制权限有点奇怪,最适合您已经接近的 ADSI 方法。 dsquery 实际上是 returns 里面有引号的字符串,所以你要么需要先去掉这些引号,要么使用不同的方法——我更喜欢 Get-ADUser:

$LdapUser = "LDAP://" + (Get-ADUser $username).distinguishedName
$User = [ADSI]$LdapUser
$User.InvokeSet("EnableRemoteControl",2)
$User.setinfo()

并为用户设置远程桌面服务配置文件路径:

$User.invokeset("terminalservicesprofilepath","\Server\Share$username")
$User.SetInfo()