# Fix calendar sharing between jim@jparkinsonaz.com and leeann@lamaddux.com
# Issue: "Calendar sharing is not available... because of permission settings"
# Cause: Default sharing policy doesn't treat custom domains as internal

# Connect to Exchange Online
Connect-ExchangeOnline

# Option 1: Check current sharing policy
Write-Host "`n=== Current Sharing Policy ===" -ForegroundColor Cyan
Get-SharingPolicy | Where-Object {$_.Default -eq $true} | Format-List Name, Enabled, Domains

# Option 2: Update the default sharing policy to allow internal domain sharing
Write-Host "`n=== Updating Sharing Policy ===" -ForegroundColor Cyan
$policy = Get-SharingPolicy | Where-Object {$_.Default -eq $true}

# Add both domains with full calendar sharing permissions
# CalendarSharingFreeBusyReviewer = Can see free/busy + subject/location
Set-SharingPolicy -Identity $policy.Name -Domains @{Add='lamaddux.com:CalendarSharingFreeBusyReviewer','jparkinsonaz.com:CalendarSharingFreeBusyReviewer'}

Write-Host "`nSharing policy updated. Both domains now allow calendar sharing." -ForegroundColor Green

# Verify the change
Write-Host "`n=== Verified Policy ===" -ForegroundColor Cyan
Get-SharingPolicy -Identity $policy.Name | Format-List Name, Enabled, Domains

Write-Host "`n=== Next Steps ===" -ForegroundColor Yellow
Write-Host "1. Jim should close and reopen Outlook"
Write-Host "2. Try sharing the calendar again with leeann@lamaddux.com"
Write-Host "3. The 'permission settings' error should be resolved"
