param ([switch]$DEBUG,[String]$FIND="team")
# FindAppts() example in PowerShell from
# http://msdn.microsoft.com/en-us/library/bb960908.aspx
#Error handling
Set-PSDebug-Strict
$ErrorActionPreference="Stop"
If ($DEBUG) {$DebugPreference="Continue"}
#Calculate dates
$myStart=get-date-Format"MM/dd/yyyy hh:mm tt"
$myEnd= (get-date).AddDays(30).tostring("MM/dd/yyyy hh:mm tt") #Or use AddMonths(1)
Write-Debug"Start: $myStart`tEnd: $myEnd"
#Construct filter for the next 30-day date range
$strRestriction="[Start] >= '$myStart' AND [End] <= '$myEnd'"
write-debug"Restriction: $strRestriction"
#Create Outlook calendar object
$objOutlookApplication=New-Object -com Outlook.Application
$objOutlookNameSpace=$objOutlookApplication.GetNameSpace("MAPI")
$objCalendar=$objOutlookNameSpace.GetDefaultFolder("olFolderCalendar")
$objItems=$objCalendar.Items
#Including recurrent appointments requires sorting by the Start property
$objItems.IncludeRecurrences =$True
$objItems.Sort("[Start]")
#Restrict the Items collection for the 30-day date range
$objItemsInDateRange=$objItems.Restrict($strRestriction)
#Construct filter for Subject containing 'team'
$PropTag= "http://schemas.microsoft.com/mapi/proptag/0x0037001E"
$strRestriction="@SQL=""$PropTag"" like '%$FIND%'"
Write-Debug"Restriction: $strRestriction"
#Restrict the last set of filtered items for the subject
$objFinalItems=$objItemsInDateRange.Restrict($strRestriction)
#Sort and print final results
$objFinalItems.Sort("[Start]")
$objFinalItems | select start, subject