我是一名新的PowerShell用户,正在尝试弄清楚如何从显示组名的组中获取用户列表。
期望的输出:
Username AD Group Department
john SG-MSOffice IT
jane SG-MSOffice Accounting
sam SG-MSOffice Accounting
thomas SG-MSOffice IT
当前输出:
代码:
Get-ADGroupMember -identity SG-MSOffice | Get-ADObject -Properties name,department,manager
输出:
Department
DistinguishedName
manager
Name
ObjectClass
ObjectGUID
答案 0 :(得分:0)
将组名存储在某处并使用Select-Object
格式化所需的输出,例如:
$groupname = "SG-MSOffice"
Get-ADGroupMember -Identity $groupname | Select-Object -Property @{n="Username";e={$_.Name}}, @{n="AD Group";e={$groupname}}, Department
我无法记住"默认" -object中是否有Department
,如果没有,您可以添加Get-ADObject
之类的内容:
$groupname = "SG-MSOffice"
Get-ADGroupMember -Identity $groupname |
Get-ADObject -Properties Name, Department |
Select-Object -Property @{n="Username";e={$_.Name}}, @{n="AD Group";e={$groupname}}, Department