SHARE
TWEET

Untitled

a guest Apr 12th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Requires -version 2.0
  2.  
  3. # https://blogs.technet.microsoft.com/heyscriptingguy/2009/12/17/hey-scripting-guy-can-i-share-my-microsoft-outlook-calendar-via-e-mail/
  4. # https://msdn.microsoft.com/en-us/library/bb208062.aspx
  5. # https://msdn.microsoft.com/en-us/library/bb208061(v=office.12).aspx
  6. # https://cjoprey.wordpress.com/archived/getting-another-user%E2%80%99s-outlook-folder%E2%80%A6/
  7.  
  8. Add-Type -AssemblyName microsoft.office.interop.outlook
  9. $olFolders = "Microsoft.Office.Interop.Outlook.OlDefaultFolders" -as [type]
  10. $olCalendarDetail = "Microsoft.Office.Interop.Outlook.olCalendarDetail" -as [type]
  11. $olCalendarMailFormat = "Microsoft.Office.Interop.Outlook.olCalendarMailFormat" -as [type]
  12. $outlook = New-Object -ComObject outlook.application
  13. $class = @"
  14. using Microsoft.Office.Interop.Outlook;public class MyOL
  15. {
  16. public MAPIFolder GetCalendar(string userName)
  17. {
  18. Application oOutlook = new Application();
  19. NameSpace oNs = oOutlook.GetNamespace("MAPI");
  20. Recipient oRep = oNs.CreateRecipient(userName);
  21. MAPIFolder calendar = oNs.GetSharedDefaultFolder(oRep, OlDefaultFolders.olFolderCalendar);
  22. return calendar;
  23. }
  24. }
  25. "@
  26. Add-Type $class -ReferencedAssemblies Microsoft.Office.Interop.Outlook
  27.  
  28. $MyOL = New-Object MyOL
  29.  
  30. # whose calendar you want
  31. $folder = $MyOL.GetCalendar("NAMEOFPERSONWHOCALENDARYOUHAVEACCESSTO")
  32.  
  33. $CalendarSharing=$folder.GetCalendarExporter()
  34.  
  35. # make the below olFullDetails or olFreeBusyOnly if you want
  36. $CalendarSharing.CalendarDetail = $olCalendarDetail::olFreeBusyAndSubject
  37.  
  38. $CalendarSharing.startDate = Get-Date
  39.  
  40. # change this to (Get-Date).addDays(7) if you want more than one day
  41. $CalendarSharing.endDate = (Get-Date).addDays(7)
  42.  
  43. $CalendarSharing.RestrictToWorkingHours = $false
  44. $CalendarSharing.IncludeAttachments = $false
  45. $CalendarSharing.IncludePrivateDetails = $false
  46.  
  47. # make the below olCalendarMailFormat::olCalendarMailFormatDailySchedule if you want
  48. $MailItem = $CalendarSharing.ForwardAsICal($olCalendarMailFormat::olCalendarMailFormatEventList)
  49.  
  50. $MailItem.DeleteAfterSubmit = $true
  51.  
  52. # configure recipient
  53. $MailItem.Recipients.Add("EMAILWHEREYOUWANTCALENDARTOGO")
  54.  
  55. $MailItem.Send()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top