Created
January 23, 2026 13:29
-
-
Save alexverboon/51ddb1ae2377ba46c3d33646313a3225 to your computer and use it in GitHub Desktop.
Bulk ICS Import
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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