SomeGuy
SomeGuy

Reputation: 1

Filtering Out Lines Not Containing Defined Values PowerShell ISE

I have a list of users and emails that I am trying to filter. I want to remove all emails that do not match what a define. For example, I only want '[email protected]' listed and '[email protected]' or '[email protected]' not listed.

This is my script:

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

As you can see, there are multiple columns (DisplayName, PrimarySmtpAddress, and Alias). I want to target 'PrimarySmtpAddress' and filter from that column.

Upvotes: 0

Views: 147

Answers (1)

postanote
postanote

Reputation: 16096

Continuing from my comment.

For example: Lots of examples for you to work from.

Select-Object PrimarySmtpAddress

Select-Object 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

PowerShell script to export display name and primary smtp address of all users

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

You can then use Where-Object or matching or comparison operators as needed.

Upvotes: 1

Related Questions