Search This Blog

Tuesday, July 31, 2018

Getting to Office 365 Calendar entries

I occasionally have to do low level analysis on items in a mailbox. Here's a how I typically have to do it.

Basically its.. 


  1. Get credentials
  2. Instantiate environment & containers
  3. Create collection
  4. Do stuff with collection

like this...

## Generic work session stuff start
##
$ExCreds = get-credential


<# I put this stuff in my profile and is a little more than needed for this topic
Enable-PSRemoting -Force
Set-ExecutionPolicy RemoteSigned -Force
Import-Module AzureAD
Import-Module LyncOnlineConnector
Import-Module MSOnline
Import-Module SkypeOnlineConnector
#>

Connect-AzureAD -Credential $ExCreds
Connect-MsolService -Credential $ExCreds
$ExchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri"https://outlook.office365.com/powershell-liveid/" -Credential $ExCreds -Authentication "Basic" -AllowRedirection
Import-PSSession $ExchangeSession
$lyncSession = New-CsOnlineSession -Credential $ExCreds
Import-PSSession $lyncSession
## 
## Generic work session stuff end


$usermail='lesley@mycompany.com'

$ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2013_SP2
$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService($ExchangeVersion)
# $service.UseDefaultCredentials = $true
$creds = New-ObjectSystem.Net.NetworkCredential($ExCreds.UserName.ToString(),$ExCreds.GetNetworkCredential().password.ToString()) 
$service.Credentials = $creds 
Add-Type -Path "C:\Program Files\Microsoft\Exchange\Web Services\2.0\Microsoft.Exchange.WebServices.dll" 
$folderid= new-objectMicrosoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Calendar,$Usermail)   
$service.Url = $uri

$Calendar = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)
$exportCollection = @()
#Define Date to Query
$StartDate = (Get-Date).AddDays(-1)
$EndDate = (Get-Date).AddDays(7)
$CalendarView = New-ObjectMicrosoft.Exchange.WebServices.Data.CalendarView($StartDate,$EndDate,1000)   
$CalendarItems = $service.FindAppointments($Calendar.Id,$CalendarView

$counter =  0''foreach ($CalendarItem in $CalendarItems){''+$counter+' '+$CalendarItem.subject;$counter++}
'''Total entries: '+$CalendarItems.TotalCount


0 Ape Pilot Check-Ins
1 Final prep for leadership meeting
2 Catch-up
Elfs Pilot Area Check In
4 Q1 ADM Pre-Review (before Pam)
5 Foundations for a Leader
6 FTL - Module 4
7 WildSpark Monthly - Don't be McFly
8 POD Pilot Visit
9 Mad Pilot Area Check-In
10 POD Staffing Plan Update to Comp
11 HR Project - Team Meeting
12 POD Career Path Policies - Open Items
13 Reporting in High
14 Foundations for a Leader - Facilitator Touch Base
15 High Reporting
16 Review 1 with Dept Mgrs
17 Weekly POD Meeting
18 Monthly Connect/Update
19 Review for POD
20 Follow Up on Staffing Plan for Org Design
21 Smart Shine
22 Dental Cleaning
23 FTL Touchbase
24 Weekly POD Project
25 Ape Pilot Check-Ins
26 Back to School Forms
27 Elfs Pilot Area Check In
28 Org Design Staffing Plan

Total entries: 29