【问题标题】:Filtering Out Lines Not Containing Defined Values PowerShell ISE过滤掉不包含定义值的行 PowerShell ISE
【发布时间】:2022-10-21 20:15:12
【问题描述】:

我有一个要过滤的用户和电子邮件列表。我想删除所有与定义不匹配的电子邮件。例如,我只希望列出 'user@example.com' 而未列出 'user@other.com' 或 'user@something.com'。

这是我的脚本:

Get-Mailbox -ResultSize 50 | Select-Object DisplayName, PrimarySmtpAddress, Alias | Sort-Object DisplayName | Out-GridView

如您所见,有多个列(DisplayName、PrimarySmtpAddress 和 Alias)。我想定位“PrimarySmtpAddress”并从该列中过滤。

【问题讨论】:

  • 这不是您所做的事情所独有的,因为它只是对象值/字符串解析。这就是 'Where-Object' cmdlet 发挥作用或简单的 RegEx 字符串匹配的原因。这是一件很常见的事情,并且在 SO 上被问过几次。使用 SO 搜索框查找它们,以及网络上的许多示例。
  • 您可以使用Get-Mailbox 提供的-FilterGet-Mailbox -Filter "PrimarySmtpAddress -Like '*other.com' -or PrimarySmtpAddress -Like '*example.com'"

标签: powershell filtering


【解决方案1】:

继续我的评论。

例如:Lots of examples for you to work from.

Select-Object PrimarySmtpAddress

选择对象 PrimarySmtpAddress

foreach ($mailbox in (Get-Mailbox -ResultSize Unlimited)) {
    $properties = @{
        PrimarySmtpAddress = $mailbox.PrimarySmtpAddress
        TotalItemSize = $mailbox | 
                        Get-MailboxStatistics | 
                        Select-Object -ExpandProperty TotalItemSize
    }
    New-Object PSObject -Property $properties
} | 
where{$_.TotalItemSize -ge 1000MB} | 
Sort-Object TotalItemSize -Descending

用于导出显示名称和主 smtp 地址的 PowerShell 脚本 所有用户

https://techcommunity.microsoft.com/t5/office-365/powershell-script-to-export-display-name-and-primary-smtp/m-p/730888

Get-Mailbox -ResultSize Unlimited |
Select-Object DisplayName,PrimarySmtpAddress,EmailAddresses,EmailAddresses | 
Export-CSV C:Temp"Exchange Online recipients.CSV" –NoTypeInformation -Encoding UTF8

然后,您可以根据需要使用 Where-Object 或匹配或比较运算符。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-06
    • 2020-02-13
    • 2020-12-19
    • 2017-08-15
    • 2013-01-13
    相关资源
    最近更新 更多