Exchange PowerShell脚本修改

时间:2015-08-27 18:46:14

标签: powershell

以下PowerShell脚本生成一个CSV文件,其中包含三列(Group,User,SAMAccountName),它们将给定通讯组的每个实例与相应的成员相关联:

$ dist = ForEach($ group in(Get-DistributionGroup -Filter {name-like" *"})){Get-DistributionGroupMember $ group |选择@ {Label =" Group&#34 ;; Expression = {$ Group.Name}},@ {Label =" User&#34 ;; Expression = {$ _.Name}},SamAccountName} $ dist |排序组,用户| Export-CSV c:\ scripts \ file.csv -NoTypeInformation

它为用户提供了一种过滤组和显示组成员的便捷方式。我的问题:是否有一种快速修改此脚本的方法,以便添加第四列显示组的属性(特别是" HiddenFromAddressListsEnabled"属性)?

1 个答案:

答案 0 :(得分:0)

只需将其添加到选择对象部分

即可
$dist = ForEach ($group in (Get-DistributionGroup -Filter {name -like "*"})) { Get-DistributionGroupMember $group | Select @{Label="Group";Expression={$Group.Name}},@{Label="User";Expression={$_.Name}},SamAccountName,HiddenFromAddressListsEnabled} $dist | Sort Group,User | Export-CSV c:\scripts\file.csv -NoTypeInformation

在SamAccountName之后看到它

获取群组的HiddenFromAddressListsEnabled:

$dist = ForEach ($group in (Get-DistributionGroup -Filter {name -like "*"})) { Get-DistributionGroupMember $group | Select @{Label="Group";Expression={$Group.Name}},@{Label="User";Expression={$_.Name}},SamAccountName,{$Group.HiddenFromAddressListsEnabled}} $dist | Sort Group,User #| Export-CSV c:\scripts\file.csv -NoTypeInformation

然而,还有另一种方法,更容易阅读和操作:

$Array = @()
$Groups = Get-DistributionGroup
Foreach ($Group in $Groups)
{
$DGMembers = Get-DistributionGroupMember $Group
Foreach ($Member in $DGMembers)
    {
    $Result = "" | Select GroupName,Member,SamAccountName,HiddenFromAddressListsEnabled
    $Result.GroupName = $Group.Name
    $Result.Member = $Member.Name
    $Result.SamAccountName = $Member.SamAccountName
    $Result.HiddenFromAddressListsEnabled = $Group.HiddenFromAddressListsEnabled
    $Array += $Result
    }

}

 $Array | Export-CSV c:\scripts\file.csv -NoTypeInformation