Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Requires -version 2.0
- # https://blogs.technet.microsoft.com/heyscriptingguy/2009/12/17/hey-scripting-guy-can-i-share-my-microsoft-outlook-calendar-via-e-mail/
- # https://msdn.microsoft.com/en-us/library/bb208062.aspx
- # https://msdn.microsoft.com/en-us/library/bb208061(v=office.12).aspx
- # https://cjoprey.wordpress.com/archived/getting-another-user%E2%80%99s-outlook-folder%E2%80%A6/
- Add-Type -AssemblyName microsoft.office.interop.outlook
- $olFolders = "Microsoft.Office.Interop.Outlook.OlDefaultFolders" -as [type]
- $olCalendarDetail = "Microsoft.Office.Interop.Outlook.olCalendarDetail" -as [type]
- $olCalendarMailFormat = "Microsoft.Office.Interop.Outlook.olCalendarMailFormat" -as [type]
- $outlook = New-Object -ComObject outlook.application
- $class = @"
- using Microsoft.Office.Interop.Outlook;public class MyOL
- {
- public MAPIFolder GetCalendar(string userName)
- {
- Application oOutlook = new Application();
- NameSpace oNs = oOutlook.GetNamespace("MAPI");
- Recipient oRep = oNs.CreateRecipient(userName);
- MAPIFolder calendar = oNs.GetSharedDefaultFolder(oRep, OlDefaultFolders.olFolderCalendar);
- return calendar;
- }
- }
- "@
- Add-Type $class -ReferencedAssemblies Microsoft.Office.Interop.Outlook
- $MyOL = New-Object MyOL
- # whose calendar you want
- $folder = $MyOL.GetCalendar("NAMEOFPERSONWHOCALENDARYOUHAVEACCESSTO")
- $CalendarSharing=$folder.GetCalendarExporter()
- # make the below olFullDetails or olFreeBusyOnly if you want
- $CalendarSharing.CalendarDetail = $olCalendarDetail::olFreeBusyAndSubject
- $CalendarSharing.startDate = Get-Date
- # change this to (Get-Date).addDays(7) if you want more than one day
- $CalendarSharing.endDate = (Get-Date).addDays(7)
- $CalendarSharing.RestrictToWorkingHours = $false
- $CalendarSharing.IncludeAttachments = $false
- $CalendarSharing.IncludePrivateDetails = $false
- # make the below olCalendarMailFormat::olCalendarMailFormatDailySchedule if you want
- $MailItem = $CalendarSharing.ForwardAsICal($olCalendarMailFormat::olCalendarMailFormatEventList)
- $MailItem.DeleteAfterSubmit = $true
- # configure recipient
- $MailItem.Recipients.Add("EMAILWHEREYOUWANTCALENDARTOGO")
- $MailItem.Send()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement