powershell - 当在字符串中给出 SAMAccountName 时,Get-ADObject -Identity 找不到对象 - 为什么?
问题描述
这很奇怪:提供带有SAMAccountName
,参数Get-ADObject
的变量Identity
找不到对象,而Filter
参数却可以。
为什么会这样?
这是我的代码:
PS C:\Projects> Get-ADObject -Filter { SamAccountName -eq $FreeSam }
DistinguishedName Name ObjectClass ObjectGUID
----------------- ---- ----------- ----------
CN=TP1-sh123456,OU=TP1-Resources ...
PS C:\Projects> Get-ADObject -Identity $FreeSam
Cannot find an object with identity: 'TP1-sh123456' under: 'DC=tstglobal,DC=tst,DC=loc'.
At line:1 char:1
+ Get-ADObject -Identity $FreeSam
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (TP1-sh123456:ADObject) [Get-ADObject], ADIdentityNotFoundException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException,Microsoft.ActiveDirectory.Management.Commands.GetADObject
解决方案
查看Get-ADObject的文档,该Identity
参数的唯一有效输入似乎是
- 专有名称
- 一个 GUID (ObjectGUID)
Get-ADUser将在这种情况下工作:
Get-ADUser -Identity $FreeSam
推荐阅读
- python-3.x - 如何在python中使用for循环打印图像?
- z3 - 在 Z3Py 中索引 BitVec 的一个元素
- c++ - C++ - 没有复制构造函数或赋值运算符的数组操作
- javascript - 幻灯片演示文稿中所有文本的 getForegroundColor() 返回空
- django - Django 无法创建或呈现评论
- spring-boot - 使用mapstruct时,返回属性为null
- parsing - Flex/Bison 编译器在标点符号处出现语法错误;总是“期待”同样的事情
- r - 如何使用(Gehan 检验和 Tarone 和 Ware 权重)比较三组的生存曲线
- java - Java:如何使用 foreach 对列表进行排序?
- c - fscanf 不检索任何值