Как прокомментировал Lee_Daily , вы удаляете все свойства, кроме Name
, выполняя Select -ExpandProperty name
. Далее, если вы хотите экспортировать в файл CSV, НЕ ИСПОЛЬЗУЙТЕ Format-Table
(ft
), потому что это только для форматирования результата на консоль.
Что вам нужно сделать, это создать массив объектов и передать его командлету Export-Csv
, как показано в приведенном ниже (непроверенном) коде:
$outputFile = '<PATH AND FILENAME FOR THE EXPORTED CSV FILE>'
Get-DistributionGroup -ResultSize Unlimited | ForEach-Object {
# The Identity parameter for Get-DistributionGroupMember specifies the distribution group
# or mail-enabled security group. You can use any value that uniquely identifies the group.
# The cmdlet also accepts the Identity parameter as pipeline input, so
# $_ | Get-DistributionGroupMember will also work.
$Members = Get-DistributionGroupMember -Identity $($_.PrimarySmtpAddress)
foreach ($member in $Members) {
[PSCustomObject]@{
GroupName = $_.DisplayName
GroupAlias = $_.Alias
GroupEmail = $_.PrimarySMTPAddress
MemberName = $member.DisplayName
MemberEmail = $member.PrimarySMTPAddress
# Maybe also add RecipientType to distinguish between users and groups?
# MemberType = $member.RecipientType
}
}
} | Export-Csv -Path $outputFile -NoTypeInformation
Надеюсь, это поможет