Powershell 7.4.2 - 获取 ADGroupMember |获取 ADUser 不起作用

问题描述 投票:0回答:1

我使用的是Powershell 7.4.2。当尝试运行如下所示的脚本时,我收到以下错误消息。

但是,这个脚本可以在 Powershell 5.1 中运行。

Get-ADGroupMember -Identity 'APPS Users' | Get-ADUser -Properties samaccountname,enabled,memberof

我的错误信息:

Get-ADUser: The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
powershell
1个回答
0
投票

注意:我无法亲自验证此解决方案。

我很惊讶这竟然有效,因为

Get-ADGroupMember
发出
ADPrincipal
实例,而
Get-ADUser
期望通过管道生成
ADUser
实例。

Get-ADGroupMember
不发出
ADUser
实例的原因是组成员不仅可以是用户,还可以是其他组,以及计算机

但是,

ADUser
ADPrincipal
 派生
,因此您可以使用
-as
过滤并转换实际上是 users 的输出对象:

Get-ADGroupMember -Identity 'APPS Users' | 
  ForEach-Object { 
   if ($user = $_ -as [Microsoft.ActiveDirectory.Management.ADUser]) { $user } 
  } |
  Get-ADUser -Properties samaccountname,enabled,memberof
© www.soinside.com 2019 - 2024. All rights reserved.