Guide
Read and Search Email in PowerShell
Nylas CLI outputs JSON, and PowerShell speaks JSON natively. That makes them a natural pair. This guide covers every way to read, search, and filter email from PowerShell -- listing unread, searching by sender or date range, reading specific messages, extracting email bodies, building PowerShell pipelines, and exporting results to CSV.
Prerequisites
You need Nylas CLI installed and authenticated. If you have not done that yet, see Gmail OAuth in PowerShell for the full setup.
# Verify you are authenticated
nylas auth whoami
# Quick test -- list one email
nylas email list --limit 1List emails
The nylas email list command returns your recent emails. Add --json to get structured output that PowerShell can parse.
# List recent emails (human-readable)
nylas email list
# List as PowerShell objects
$emails = nylas email list --json | ConvertFrom-Json
$emails | Format-Table subject, from, date -AutoSizeList unread emails
# List only unread emails
$unread = nylas email list --unread --json | ConvertFrom-Json
Write-Host "You have $($unread.Count) unread emails"
$unread | Format-Table subject, from -AutoSizeFilter by sender
# List emails from a specific sender
$fromAlice = nylas email list --from "alice@company.com" --json |
ConvertFrom-Json
$fromAlice | Format-Table subject, date -AutoSizeFilter by folder
# List emails in a specific folder
$sent = nylas email list --folder "sent" --json | ConvertFrom-Json
$sent | Select-Object -First 5 | Format-Table subject, to, date -AutoSizeSearch emails
The nylas email search command takes a search query as a positional argument. It searches across subject, body, sender, and recipients.
# Search for a keyword
nylas email search "quarterly report"
# Search and get PowerShell objects
$results = nylas email search "invoice" --json | ConvertFrom-Json
$results | Format-Table subject, from, date -AutoSizeSearch by sender
# Search for emails from a specific person
$results = nylas email search "from:ceo@company.com" --json |
ConvertFrom-Json
$results | ForEach-Object {
Write-Host "$($_.date) - $($_.subject)"
}Search by date range
# Emails from the last week
$results = nylas email search "after:2026-03-06 before:2026-03-13" --json |
ConvertFrom-Json
Write-Host "Found $($results.Count) emails in date range"
$results | Format-Table subject, from, date -AutoSizeCombine search filters
# Search for emails from a sender within a date range
$results = nylas email search `
"from:alice@company.com after:2026-03-01" --json |
ConvertFrom-Json
$results | Format-Table subject, date -AutoSizeRead a specific message
The nylas email read command takes a message ID as a positional argument and returns the full email content including body.
# First, get the message ID from a list
$emails = nylas email list --json --limit 5 | ConvertFrom-Json
$firstId = $emails[0].id
# Read the full message
$message = nylas email read $firstId --json | ConvertFrom-Json
Write-Host "Subject: $($message.subject)"
Write-Host "From: $($message.from)"
Write-Host "Date: $($message.date)"
Write-Host ""
Write-Host $message.bodyExtract and process email bodies
# Extract just the text body from recent emails
$emails = nylas email list --json --limit 10 | ConvertFrom-Json
$emails | ForEach-Object {
$msg = nylas email read $_.id --json | ConvertFrom-Json
[PSCustomObject]@{
Subject = $_.subject
From = $_.from
Body = $msg.body.Substring(0, [Math]::Min(100, $msg.body.Length)) + "..."
}
} | Format-Table -WrapView email threads
# Show a full email thread
$emails = nylas email list --json --limit 5 | ConvertFrom-Json
$threadId = $emails[0].thread_id
nylas email threads show $threadIdPowerShell pipeline patterns
The real power comes from combining Nylas CLI's JSON output with PowerShell's object pipeline. Here are common patterns:
# Pattern 1: Filter emails with Where-Object
$emails = nylas email list --json --limit 50 | ConvertFrom-Json
$urgent = $emails | Where-Object {
$_.subject -match "urgent|asap|critical"
}
Write-Host "Found $($urgent.Count) urgent emails"
# Pattern 2: Sort by date
$emails | Sort-Object date -Descending |
Select-Object -First 10 |
Format-Table subject, from, date
# Pattern 3: Group by sender
$emails | Group-Object from |
Sort-Object Count -Descending |
Select-Object @{N="Sender";E={$_.Name}}, Count |
Format-Table -AutoSize
# Pattern 4: Count emails per day
$emails | Group-Object { ($_.date -split "T")[0] } |
Sort-Object Name |
Select-Object @{N="Date";E={$_.Name}}, Count |
Format-Table -AutoSizeExport emails to CSV
# Export email list to CSV
nylas email list --json --limit 100 | ConvertFrom-Json |
Select-Object subject, from, date, unread |
Export-Csv -Path emails.csv -NoTypeInformation
Write-Host "Exported to emails.csv"
Get-Content emails.csv | Select-Object -First 5# Export search results to CSV
nylas email search "project update" --json | ConvertFrom-Json |
Select-Object subject, from, date |
Export-Csv -Path project-updates.csv -NoTypeInformationAdvanced: email monitoring script
Here is a complete PowerShell script that monitors for new emails from important senders:
# email-monitor.ps1 -- Check for important unread emails
param(
[string[]]$ImportantSenders = @(
"boss@company.com",
"cto@company.com",
"hr@company.com"
),
[int]$Limit = 50
)
$unread = nylas email list --unread --json --limit $Limit |
ConvertFrom-Json
$important = $unread | Where-Object {
$sender = $_.from
$ImportantSenders | Where-Object { $sender -match $_ }
}
if ($important.Count -eq 0) {
Write-Host "No important unread emails." -ForegroundColor Green
exit 0
}
Write-Host "Important unread emails:" -ForegroundColor Yellow
Write-Host "========================" -ForegroundColor Yellow
$important | ForEach-Object {
Write-Host ""
Write-Host "From: $($_.from)" -ForegroundColor Cyan
Write-Host "Subject: $($_.subject)"
Write-Host "Date: $($_.date)"
}# Run the monitoring script
.\email-monitor.ps1
# With custom senders
.\email-monitor.ps1 -ImportantSenders @("vp@company.com", "client@partner.com")Frequently asked questions
How do I list unread emails in PowerShell?
Run nylas email list --unread --json | ConvertFrom-Json. This returns unread emails as PowerShell objects that you can filter with Where-Object, sort with Sort-Object, and format with Format-Table.
Can I search email by date range?
Yes. Use nylas email search "after:2026-03-01 before:2026-03-13" --json to search within a date range. You can combine date filters with sender, subject, or keyword filters in the same query.
How do I export emails to CSV?
Pipe the JSON output through ConvertFrom-Json and Export-Csv: nylas email list --json | ConvertFrom-Json | Select-Object subject, from, date | Export-Csv emails.csv -NoTypeInformation. This creates a CSV file you can open in Excel.
Does this work with PowerShell 5.1?
Yes. Nylas CLI works with both Windows PowerShell 5.1 and PowerShell 7+. The CLI is a standalone Go binary and does not depend on any PowerShell modules. ConvertFrom-Json is available in both versions.
Next steps
- Gmail OAuth in PowerShell -- set up authentication if you have not already
- Send email from PowerShell -- compose, reply, and send with attachments
- Replace Send-MailMessage -- migrate from the deprecated cmdlet
- Full command reference -- every flag and subcommand