powershell - 调用 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
解决方案
write-host
只能接受一串文本。
$User
不是字符串,它更像是一个数组,因为它包含两行信息。它包含“distinguishedName”和“Path”。
您可以键入:
Write-Host $User.path
Write-Host $User.distinguishedName
问题是这个命令:
$User.InvokeSet("EnableRemoteControl",5)
你为什么用5?用 2 测试,它似乎工作
$User.InvokeSet("EnableRemoteControl",2)
推荐阅读
- android - 执行功能,无论活动完成
- c# - 替换支持集合时保持 WPF DataGrid 排序
- api - 在 Playstore 中重新发布应用后 API 无法工作
- python - 如何在 Scrapy 爬虫中进行代理?
- python - Odoo14基于用户组隐藏菜单系统托盘?
- anylogic - 如何根据交货地点和库存水平批量代理
- amazon-ec2 - 如何在 Lambda 中从警报中提取特定信息(如实例 ID)(使用成本指标)
- vb.net - VB.NET Docker 失败
- sql - 撤消 COPY 命令 redshift | 从红移中删除
- c++ - 如何组合具有相同代码的两个模板函数?