我想要得到如下的输出。
我现在的输出:
Name Active PrimarySmtpAddress
---- ------ ------------------
DG_Group1 True mail1@contoso.com
DG_Group2 False mail2@contoso.com
DG_Group3 True mail3@contoso.com
我想要的输出:
mail1@contoso.com
mail2@contoso.com
mail3@contoso.com
脚本:
$DistroLists = Get-DistributionGroup -ResultSize Unlimited
$MessageTrace = Get-MessageTrace -RecipientAddress $DistroLists.PrimarySmtpAddress -startdate (Get-Date).AddDays(-8) -EndDate (Get-Date)
$DistroLists |
Foreach-Object {
$_ | Add-Member -MemberType NoteProperty -Name Active -Value (
$_.PrimarySmtpAddress -in $MessageTrace.RecipientAddress
) -PassThru
} |
Select-Object Name, Active, PrimarySmtpAddress | Where-Object Active -EQ "FALSE"
Out-File C:output.txt
您可以使用Select-Object -ExpandProperty
或ForEach-Object -MemberName
从一个或多个管道输入对象中仅获取特定属性的值:
... |Select-Object Name, Active, PrimarySmtpAddress | Where-Object Active -eq $false | ForEach-Object -MemberName PrimarySmtpAddress | Out-File...
您可以跳过前两行,并使用空格字符拆分该行。最后选择下面给出的最后一列:
Get-Content C:Projectslogtext.txt | Select-Object -Skip 2 | ForEach-Object { "$(($_
-split 's+',3)[2])" }
mail1@contoso.com
mail2@contoso.com
mail3@contoso.com