- 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.
Showing posts with label Outlook.Application. Show all posts
Showing posts with label Outlook.Application. Show all posts
Saturday, 12 October 2013
Get-OLCalendarItem
Saturday, 20 March 2010
Get-OutlookStores.ps1
- <#
- .SYNOPSIS
- This script uses the Outlook COM object to
- display the data stores in the current profile
- .DESCRIPTION
- This script creates an Outlook object, displays
- user information, and the stores currently
- attached to the profile.
- .NOTES
- File Name : Get-OutlookStores.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- .EXAMPLE
- PSH [C:\foo]: .\Get-OutlookStores.ps1'
- Current profile has the following configured accounts:
- Account Type User Name SMTP Address
- ------------ --------- ------------
- Microsoft Exchange Thomas.Lee Thomas.Lee@cookham.net
- thomas_lee@hotmail.com Thomas Lee (MSN) thomas_lee@hotmail.com
- Exchange Offile Folder Store:
- C:\Users\tfl\AppData\Local\Microsoft\Outlook\outlook0.ost
- PST Files
- Display Name File Path
- ------------ ---------
- Archive Folders C:\Users\tfl\AppData\Local\Microsoft\Outlook\archive.pst
- #>
- ##
- # Begin Script
- ##
- # Create Outlook object
- $Outlook = New-Object -ComObject Outlook.Application
- $stores = $Outlook.Session.Stores
- $accounts = $outlook.session.accounts
- # Basic information
- "Current profile has the following configured accounts:"
- $dn = @{label = "Account Type"; expression={$_.displayname}}
- $un = @{label = "User Name"; expression = {$_.username}}
- $sm = @{label = "SMTP Address"; expression = {$_.smtpaddress}}
- $accounts | Format-Table -AutoSize $dn,$un,$sm
- # Check number of stores > 0
- if ($stores.Count -le 0) {"No stores found"; return}
- # Outlook Off-Line folder store
- $ost = $stores | where{$_.filepath -match ".ost$"}
- if (!$ost)
- {
- "No Outlook Offline Folder store found"
- }
- else
- {
- "Exchange Offile Folder Store:"
- $ost | ft filepath -HideTableHeaders
- }
- # PST Files
- $pst = $stores | where {$_.filepath -match ".pst$"}
- if (!$pst)
- {
- "No PST files found"
- }
- else
- {
- "PST Files"
- $dn = @{label = "Display Name"; expression={$_.displayname}}
- $fn = @{label = "File Path"; expression={$_.filepath}}
- $pst | ft $dn,$fn
- }
- # End Script
Labels:
Outlook,
Outlook.Application,
PowerShell scripts,
Script,
scripts
Subscribe to:
Posts (Atom)