首页 > 解决方案 > 调用 InvokeSet 异常,在缓存中找不到目录属性

问题描述

运行以下代码时,我收到 Exception calling "InvokeSet" with "2" argument(s): "The directory property cannot be found in the cache."在线错误,此错误存在是因为变量为空的问题。使用 Write-Host 后,我​​得出的结论是该$User = [ADSI]$LdapUser行是导致问题的行。

#Set Remote Control Settings Permissions 
        $LdapUser = "LDAP://" + (Get-ADUser $username).distinguishedName
        Write-Host $LdapUser
        $User = [ADSI]$LdapUser
        Write-Host $User
        $User.InvokeSet("EnableRemoteControl",5)
        $User.InvokeSet("TerminalServicesHomeDrive","U:\")
        $User.setinfo()

$LdapUser显示器的 Write-Host 命令"LDAP://CN=Test Taco,CN=Users,DC=blah,DC=org"是正确的,但是显示器的 Write-Host 命令 为什么变量$User显示错误的信息,我该如何解决?System.DirectoryServices.DirectoryEntry $User

标签: powershellldapadsi

解决方案


write-host只能接受一串文本。

$User不是字符串,它更像是一个数组,因为它包含两行信息。它包含“distinguishedName”和“Path”。

您可以键入:

Write-Host $User.path
Write-Host $User.distinguishedName

问题是这个命令:

$User.InvokeSet("EnableRemoteControl",5)

你为什么用5?用 2 测试,它似乎工作

$User.InvokeSet("EnableRemoteControl",2)

推荐阅读