- Function Get-OLCalendarItem {
- <#
- .SYNOPSIS
- A function to retreive Outlook Calender items between two dates.
- Returns PSobjects containing each item.
- .DESCRIPTION
- The function opens one's outlook calender, then retrieves the items.
- The function takes 2 parameter: start, end - items are returned that
- start betweween these two dates.
- .NOTES
- File Name : Get-OLCalendarItem
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 3.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- .EXAMPLE
- Left as an exercise for the reader
- #>
- [CmdletBinding()]
- Param (
- $start = $(Get-Date) ,
- $end = $((Get-date).AddMonths(1))
- )
- Write-Verbose "Returning objects between: $($start.tostring()) and $($end.tostring())"
- # Load Outlook interop and Outlook iteslf
- [Reflection.Assembly]::LoadWithPartialname("Microsoft.Office.Interop.Outlook") | out-null
- $Outlook = new-object -comobject outlook.application
- # Get OL default folders
- $OlFolders = "Microsoft.Office.Interop.Outlook.OlDefaultFolders" -as [type]
- $Namespace = $Outlook.GetNameSpace("MAPI")
- $Calendar = $namespace.GetDefaultFolder($olFolders::olFolderCalendar)
- Write-Verbose "There are $($calendar.items.count) items in the calender in total"
- # Now return psobjects for all items between 2 dates
- ForEach ($citem in ($Calendar.Items | sort start)) {
- #Write-Verbose "Processing [$($citem.Subject)] Starting: [$($Citem.Start)]"
- If ($citem.start -ge $start -and $citem.start -LE $end) {
- $CalHT =[ordered] @{
- Subject = $($Citem.Subject)
- Location = $($Citem.Location);
- Start = $(Get-Date $Citem.Start);
- StartUTC = $(Get-Date $Citem.StartUTC);
- End = $(Get-Date $Citem.End);
- EndUTC = $(Get-Date $Citem.EndUTC);
- Duration = $($Citem.Duration);
- Importance = $($Citem.Importance);
- IsRecurring = $($Citem.IsRecurring);
- AllDayEvent = $($citem.AllDayEvent);
- Sensitivity = $($Citem.Sensitivity);
- ReminderSet = $($Citem.ReminderSet);
- CreationTime = $($Citem.CreationTime);
- LastModificationTime = $($Citem.LastModificationTime);
- Body = $($Citem.Body);
- }
- # Write the item out as a custom item
- $o=New-Object PSobject -Property $CalHT
- Write-Output $o
- }
- } #End of foreach
- } # End of function
- Set-Alias GCALI Get-OLCalendarItem
This blog contains PowerShell scripts, more PowerShell scripts and still more PowerShell scripts. Occasionally you may see some organisational posts.
Saturday, 12 October 2013
Get-OLCalendarItem
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment