我使用的是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.
注意:我无法亲自验证此解决方案。
我很惊讶这竟然有效,因为
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