Skip to content

Instantly share code, notes, and snippets.

@alexverboon
Created January 23, 2026 13:29
Show Gist options
  • Select an option

  • Save alexverboon/51ddb1ae2377ba46c3d33646313a3225 to your computer and use it in GitHub Desktop.

Select an option

Save alexverboon/51ddb1ae2377ba46c3d33646313a3225 to your computer and use it in GitHub Desktop.
Bulk ICS Import
param(
[Parameter(Mandatory = $true)]
[string]$ICSFolderPath
)
# Validate folder
if (-not (Test-Path $ICSFolderPath)) {
Write-Host "❌ The folder path does not exist: $ICSFolderPath" -ForegroundColor Red
exit
}
Write-Host "πŸ“ Importing all .ics files from: $ICSFolderPath" -ForegroundColor Cyan
# Get Outlook COM object
try {
$outlook = New-Object -ComObject Outlook.Application
} catch {
Write-Host "❌ Outlook is not installed or cannot be automated." -ForegroundColor Red
exit
}
# Calendar folder
$namespace = $outlook.GetNamespace("MAPI")
$calendar = $namespace.GetDefaultFolder(9) # olFolderCalendar = 9
# Process ICS files
$icsFiles = Get-ChildItem -Path $ICSFolderPath -Filter *.ics
if ($icsFiles.Count -eq 0) {
Write-Host "⚠️ No ICS files found in folder." -ForegroundColor Yellow
exit
}
foreach ($file in $icsFiles) {
Write-Host "πŸ“Œ Importing: $($file.Name)"
try {
# Import ICS file content directly
$appointment = $calendar.Items.Add(1) # olAppointmentItem = 1
# Read and import ICS file
$icsContent = Get-Content -Path $file.FullName -Raw
# Use Import method to load ICS data
$tempItem = $namespace.OpenSharedItem($file.FullName)
# Copy properties to new appointment
$appointment.Subject = $tempItem.Subject
$appointment.Start = $tempItem.Start
$appointment.End = $tempItem.End
$appointment.Location = $tempItem.Location
$appointment.Body = $tempItem.Body
$appointment.ReminderSet = $tempItem.ReminderSet
$appointment.ReminderMinutesBeforeStart = $tempItem.ReminderMinutesBeforeStart
# Save to calendar
$appointment.Save()
Write-Host " βœ” Imported successfully" -ForegroundColor Green
}
catch {
Write-Host " ❌ Failed to import $($file.Name): $($_.Exception.Message)" -ForegroundColor Red
}
}
Write-Host "πŸŽ‰ Done! All ICS files processed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment