我希望看到写一个班轮的清洁方式是什么。
Get-AdGroup -Filter * -Properties Name,Description,whenCreated,whenChanged,ObjectClass,GroupCategory,GroupScope,SamAccountName,DistinguishedName |
Sort-Object Name |
Select-Object Name,Description,whenCreated,whenChanged,ObjectClass,GroupCategory,GroupScope,SamAccountName,DistinguishedName |
Select *,@{Name="Members";Expression={Get-ADGroupMember $_.Name | %{$_.SamAccountName+';'}}} |
Export-Csv -Path .\Group.csv -NoTypeInformation
答案 0 :(得分:1)
并将属性名称分配给变量,以便将它们全部写出两次,并将Select-Object
和select
组合在一起:
$properties = "Name,Description,whenCreated,whenChanged,ObjectClass,GroupCategory,GroupScope,SamAccountName,DistinguishedName";
Get-AdGroup -filter * -properties $properties |
Select-Object $properties,@{Name="Members";Expression={Get-ADGroupMember $_.Name | %{$_.SamAccountName+';'}}} |
Sort-Object Name |
Export-Csv -Path .\Group.csv -NoTypeInformation
注意:这是一个单行命令,但为了便于阅读,我将其分开。