Never miss an appointment again with PowerShell

If your anything like me then you spend most of your time in PowerShell and sometimes forget to check your appointments in Outlook, wouldn’t it be great if you could see your Outlook calendar straight in PowerShell ?

After doing a little searching and altering this post, I created a nice function for PowerShell which I called

Get-Outlookappointments

This function by default will show 7 days worth of items in your PowerShell window, you can pass it some parameters, NumDays will show that number of days appointments….

SNAGHTML4a7b217

Or you can specify a star date and end date using the parameters “Start” and “End”.

This makes a great addition to your PowerShell profile so every time you open PowerShell you are reminded of what you have coming up for the next week and you can call the function over and over in your PowerShell session when needed.

Script

Function Get-OutlookAppointments {
	param ( 
			[Int] $NumDays = 7,
			[DateTime] $Start = [DateTime]::Now ,
	      	[DateTime] $End   = [DateTime]::Now.AddDays($NumDays)
	)

	Process {
		$outlook = New-Object -ComObject Outlook.Application

		$session = $outlook.Session
		$session.Logon()

		$apptItems = $session.GetDefaultFolder(9).Items
		$apptItems.Sort("[Start]")
		$apptItems.IncludeRecurrences = $true
		$apptItems = $apptItems

		$restriction = "[End] >= '{0}' AND [Start] <= '{1}'" -f $Start.ToString("g"), $End.ToString("g")

		foreach($appt in $apptItems.Restrict($restriction))
		{
		    If (([DateTime]$Appt.Start -[DateTime]$appt.End).Days -eq "-1") {
				"All Day Event : {0} Organized by {1}" -f $appt.Subject, $appt.Organizer
			}
			Else {
				"{0:ddd hh:mmtt} - {1:hh:mmtt} : {2} Organized by {3}" -f [DateTime]$appt.Start, [DateTime]$appt.End, $appt.Subject, $appt.Organizer
			}
			
		}

		$outlook = $session = $null;
	}
}

Get-OutlookAppointments

9 thoughts on “Never miss an appointment again with PowerShell”

Leave a Reply