【问题标题】:The member does not exist? Powershell script会员不存在? Powershell 脚本
【发布时间】:2018-02-09 14:19:37
【问题描述】:

我一直在阅读一些问题,并且可以找到有关创建脚本的信息,但似乎没有使用对象类型“计算机”。

抱歉,如果这更适合超级用户。但这仍处于脚本级别,因此我认为最好将其放置在此处。

这是我的脚本。我想将域注册服务器(计算机)添加到一系列服务器上的性能监视器用户组。

$ComputerName = Read-Host "Remote Computer name:"
$PmuGroup = [ADSI]"WinNT://$ComputerName/Performance Monitor Users,group"
$User = [ADSI]"WinNT://DOMAIN/ServerName,computer"
$PmuGroup.Add($User.Path) 

显示如下错误:

Exception calling "Add" with "1" argument(s): "A member could not be added to 
or removed from the local group because
the member does not exist.
"
At line:1 char:1
+ $AdminGroup.Add($User.Path)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI

如果我在 PS 中输入$user,它会返回路径并似乎找到了机器。

按照 cmets 的建议尝试不使用 .path;

PS C:\WINDOWS> $PmuGroup.Add($User)
Exception calling "Add" with "1" argument(s): "Type mismatch. (Exception 
from HRESULT: 0x80020005
(DISP_E_TYPEMISMATCH))"
At line:1 char:1
+ $PmuGroup.Add($User)
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI

这是我的脚本的错误吗/任何人都可以就其中的任何错误提出建议吗? 有关信息:域/服务器名称不是正在使用的。我已经从这里删除了实际名称。

【问题讨论】:

  • 你试过$PmuGroup.Add($User)吗?
  • @MathiasR.Jessen 是的,错误略有不同。我已经修改了问题。
  • 尝试在一台服务器上手动执行此操作(使用 GUI 或 net localgroup),看看它是否会吐出相同(或类似的)错误,以确保它只是您的脚本不起作用并且消除 AD 本身的某些东西被破坏的可能性。另外,这个脚本是在服务器本地执行还是通过Invoke-Command远程执行?当必须针对域验证某些内容时,后者可能会导致双跳身份验证问题。

标签: powershell adsi


【解决方案1】:

计算机帐户的 samAccountName 始终以 $ 结尾:

$ComputerName = Read-Host "Remote Computer name:"
$PmuGroup = [ADSI]"WinNT://$ComputerName/Performance Monitor Users,group"
$Computer = [ADSI]"WinNT://DOMAIN/ServerName$"
$PmuGroup.Add($Computer.Path) 

【讨论】:

  • @Bill_Stewart 奇怪。对我来说很好。我在 Win 7/PS 5.1,远程系统是 Server 2012 R2/PS 4。
  • 非常感谢。这已经奏效了。我没有意识到计算机帐户必须以 $ 结尾,我也没有意识到您不需要在它之后使用对象类型“计算机”。这非常有效。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多