Guide

Automate Email and Calendar in PowerShell

Build cross-provider email and calendar automation workflows in PowerShell using Nylas CLI. Read emails, create events, check availability, schedule meetings from email content, and build daily digests. Works with Gmail, Outlook, Exchange, and any connected provider.

Prerequisites

# Install Nylas CLI (one-liner for PowerShell)
irm https://cli.nylas.com/install.ps1 | iex

# Or install with Go (requires Go 1.21+)
# go install github.com/nylas/cli/cmd/nylas@latest

# Authenticate (one-time, opens browser for OAuth)
nylas auth login

# Verify email access
nylas email list --limit 1 --json | ConvertFrom-Json

# Verify calendar access
nylas calendar events list --json | ConvertFrom-Json

Read and search emails

The foundation of any email automation is reading and filtering messages. Nylas CLI returns JSON that PowerShell can natively parse:

# List recent emails
$emails = nylas email list --json --limit 10 | ConvertFrom-Json
$emails | Select-Object id, subject, @{N='from';E={$_.from.email}}, date

# Search for specific emails
$results = nylas email search "meeting invite" --json --limit 10 | `
  ConvertFrom-Json
$results | Format-Table subject, @{N='from';E={$_.from.email}}, date

# Read a specific email
$msg = nylas email read <message-id> --json | ConvertFrom-Json
Write-Host "From: $($msg.from.email)"
Write-Host "Subject: $($msg.subject)"
Write-Host "Body: $($msg.body.Substring(0, 200))..."

List and create calendar events

Calendar commands follow the same JSON pattern. List events, create new ones, and parse the results:

# List upcoming events
$events = nylas calendar events list --json | ConvertFrom-Json
$events | Select-Object title, `
  @{N='start';E={$_.when.start_time}}, `
  @{N='end';E={$_.when.end_time}}, `
  @{N='participants';E={($_.participants | ForEach-Object { $_.email }) -join ', '}}

# Create a new event
nylas calendar events create `
  --title "Team Standup" `
  --start "2026-03-15T09:00:00" `
  --end "2026-03-15T09:30:00" `
  --participants "alice@example.com,bob@example.com" `
  --json | ConvertFrom-Json

# Create an event with a description
nylas calendar events create `
  --title "Project Review" `
  --start "2026-03-16T14:00:00" `
  --end "2026-03-16T15:00:00" `
  --description "Review Q1 deliverables and plan Q2 roadmap" `
  --json | ConvertFrom-Json

Check availability before scheduling

Before creating events, check free/busy status to avoid conflicts:

# Check availability for a given time window
$availability = nylas calendar availability check `
  --start "2026-03-15T09:00:00" `
  --end "2026-03-15T17:00:00" `
  --json | ConvertFrom-Json

# Display free slots
$availability.time_slots | `
  Where-Object { $_.status -eq "free" } | `
  ForEach-Object {
      Write-Host "Free: $($_.start_time) to $($_.end_time)"
  }

# Find the first available 30-minute slot
$freeSlot = $availability.time_slots | `
  Where-Object { $_.status -eq "free" } | `
  Select-Object -First 1

if ($freeSlot) {
    Write-Host "Next available: $($freeSlot.start_time)"
} else {
    Write-Host "No availability in this window"
}

Extract meeting requests from email and create events

Search your inbox for meeting-related emails and create calendar events from their content:

# Search for emails about meetings this week
$meetingEmails = nylas email search "meeting this week" --json --limit 10 | `
  ConvertFrom-Json

# Display what we found
$meetingEmails | ForEach-Object {
    Write-Host "From: $($_.from.email)"
    Write-Host "Subject: $($_.subject)"
    Write-Host "---"
}

# Create an event from an email conversation
# (after you identify the relevant details from the email)
$msg = nylas email read <message-id> --json | ConvertFrom-Json

nylas calendar events create `
  --title "Follow-up: $($msg.subject)" `
  --start "2026-03-15T10:00:00" `
  --end "2026-03-15T10:30:00" `
  --participants $msg.from.email `
  --description "Follow-up on email: $($msg.subject)" `
  --json | ConvertFrom-Json

Write-Host "Event created for follow-up with $($msg.from.email)"

Build a daily digest of upcoming events

Create a PowerShell script that summarizes today's emails and calendar events:

# daily-digest.ps1 — Run each morning for a summary

$today = Get-Date -Format "yyyy-MM-dd"
Write-Host "=== Daily Digest for $today ===" -ForegroundColor Cyan

# Upcoming calendar events
Write-Host "`nCalendar Events:" -ForegroundColor Green
$events = nylas calendar events list --json | ConvertFrom-Json
if ($events.Count -eq 0) {
    Write-Host "  No events scheduled"
} else {
    $events | ForEach-Object {
        $start = $_.when.start_time
        $participants = ($_.participants | ForEach-Object { $_.email }) -join ', '
        Write-Host "  $start - $($_.title)"
        if ($participants) {
            Write-Host "    With: $participants" -ForegroundColor DarkGray
        }
    }
}

# Unread emails summary
Write-Host "`nUnread Emails:" -ForegroundColor Green
$emails = nylas email list --json --limit 10 --unread | ConvertFrom-Json
if ($emails.Count -eq 0) {
    Write-Host "  Inbox zero!"
} else {
    Write-Host "  $($emails.Count) unread messages"
    $emails | ForEach-Object {
        Write-Host "  From: $($_.from.email)$($_.subject)"
    }
}

# Emails with attachments waiting
Write-Host "`nEmails with Attachments:" -ForegroundColor Green
$withAttach = nylas email list --has-attachment --json --limit 5 | ConvertFrom-Json
$withAttach | ForEach-Object {
    Write-Host "  $($_.subject) (from $($_.from.email))"
}

Auto-reply with availability

Check your calendar and send an email with your open time slots:

# Check availability for next week and send it to someone
$nextMonday = (Get-Date).AddDays(8 - (Get-Date).DayOfWeek.value__)
$nextFriday = $nextMonday.AddDays(4).AddHours(17)

$availability = nylas calendar availability check `
  --start $nextMonday.ToString("yyyy-MM-ddT09:00:00") `
  --end $nextFriday.ToString("yyyy-MM-ddTHH:mm:ss") `
  --json | ConvertFrom-Json

# Build a human-readable list of free slots
$freeSlots = $availability.time_slots | `
  Where-Object { $_.status -eq "free" } | `
  ForEach-Object {
      $start = [DateTime]::Parse($_.start_time)
      "$($start.ToString('dddd MMM d')): $($start.ToString('h:mm tt')) - $([DateTime]::Parse($_.end_time).ToString('h:mm tt'))"
  }

$body = "Here are my available times next week:`n`n"
$body += ($freeSlots -join "`n")
$body += "`n`nLet me know which slot works best."

# Send the availability email
nylas email send `
  --to "colleague@example.com" `
  --subject "My availability next week" `
  --body $body `
  --yes --json | ConvertFrom-Json

Write-Host "Availability email sent with $($freeSlots.Count) open slots"

Schedule follow-up events from email threads

Search for emails that need follow-ups and create calendar reminders:

# Find emails you need to follow up on
$followups = nylas email search "action required" --json --limit 10 | `
  ConvertFrom-Json

# Create a follow-up event for each
$followups | ForEach-Object {
    $msg = $_
    $followupDate = (Get-Date).AddDays(2).ToString("yyyy-MM-dd")

    nylas calendar events create `
      --title "Follow up: $($msg.subject.Substring(0, [Math]::Min(50, $msg.subject.Length)))" `
      --start "$($followupDate)T10:00:00" `
      --end "$($followupDate)T10:15:00" `
      --description "Follow up on email from $($msg.from.email): $($msg.subject)" `
      --json | Out-Null

    Write-Host "Scheduled follow-up for: $($msg.subject)"
}

Write-Host "Created $($followups.Count) follow-up reminders"

Meeting prep — pull related emails before an event

Before a meeting, search your inbox for emails related to each participant:

# Get today's events and find related emails for each
$events = nylas calendar events list --json | ConvertFrom-Json

$events | ForEach-Object {
    $event = $_
    Write-Host "`n=== $($event.title) ===" -ForegroundColor Cyan

    $event.participants | ForEach-Object {
        $email = $_.email
        Write-Host "Recent emails from $email :" -ForegroundColor Yellow

        $related = nylas email search "from:$email" --json --limit 3 | `
          ConvertFrom-Json

        if ($related.Count -eq 0) {
            Write-Host "  (none)"
        } else {
            $related | ForEach-Object {
                Write-Host "  $($_.date)$($_.subject)"
            }
        }
    }
}

Run as a scheduled task

Turn any of these scripts into a Windows Scheduled Task for unattended automation:

# Save any script above as, e.g., C:\Scripts\daily-digest.ps1
# Then register it as a scheduled task:

$action = New-ScheduledTaskAction `
  -Execute "pwsh.exe" `
  -Argument "-NoProfile -File C:\Scripts\daily-digest.ps1"

$trigger = New-ScheduledTaskTrigger `
  -Daily `
  -At "8:00AM"

Register-ScheduledTask `
  -TaskName "Nylas Daily Digest" `
  -Action $action `
  -Trigger $trigger `
  -Description "Morning email and calendar summary"

# To run it immediately for testing:
Start-ScheduledTask -TaskName "Nylas Daily Digest"

Frequently asked questions

Can I automate email and calendar together in PowerShell?

Yes. Nylas CLI provides both email commands (nylas email list, nylas email search, nylas email send) and calendar commands (nylas calendar events list, nylas calendar events create, nylas calendar availability check). Pipe JSON output through ConvertFrom-Json to build workflows that span both domains.

How do I create a calendar event from PowerShell?

Use nylas calendar events create --title "Meeting" --start "2026-03-15T10:00:00" --end "2026-03-15T11:00:00" --json. Add --participants for attendees and --description for details. The CLI handles provider differences automatically.

Does Nylas CLI calendar work with Google Calendar and Outlook?

Yes. Nylas CLI normalizes calendar APIs across Google Calendar, Microsoft Outlook, Exchange, and other providers. The same commands work regardless of which provider is connected. Authenticate once with nylas auth login and the CLI handles the rest.

How do I check availability before scheduling a meeting?

Use nylas calendar availability check --start "..." --end "..." --json to get free/busy slots. Parse with ConvertFrom-Json, filter with Where-Object { $_.status -eq "free" }, and create events in open windows.


Next steps