Logical assistance within outlook calendar script

Tagged: 

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 2 years ago.

  • Author
    Posts
  • #20575
    Profile photo of Michael Orellana
    Michael Orellana
    Participant

    Hello All,

    As always, thank you very much for the help that is always provided in this forum. I have question regarding a script I wrote that copies all events from a shared outlook calendar to my outlook calendar and sets reminders so I can be reminded of important work events. Now the script works, but I want to add another feature to the script. That would be checking for changes in time and or cancellations of meetings and updating accordingly.
    The code is below, and like I said it works, but I am just looking for input on how you would go about looking for these changes and modifying them. I am very much still an amateur with powershell so I accept any and all criticism.

    try{
            # Powershell creates outlook object so we can interact with it
            $objOutlook= New-Object -ComObject Outlook.Application -ErrorAction Stop
    }catch{ 
            Write-Warning "May need to edit registry key 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\SubSystems\Windows' 
                            Or check your permissions to lifesize calendar. Check Desktop for Errors"
         }
                             
    # Grabbing the system date
    $date = Get-Date
    
    # looks a month back and changes format of date
    $startDate = $date.Adddays(-2).toshortdatestring()
    
    
    # Tells powershell what namespace to use. MAPI is the only namespace for the outlook application to use
    $objNamespace = $objOutlook.GetNameSpace("MAPI")
    
    # Gets the default calendar of the user running the script
    $objDefault = $objNamespace.GetDefaultFolder("olFolderCalendar")
    
    # Collects the Conversation Index of each event in default calendar
    $colDefault = $objDefault.Items | Where-Object {$_.start -ge $StartDate}
    
    # Grabs all the items from the lifesize calendar
    $objFolder = $objNamespace.Folders.Item("CA - Mobile Lifesize Unit #1").folders.Item("calendar")
        
    # Collects all the events from the Lifesize calendar into a collection for us to use in the foreach loop.
    $colItems = $objFolder.Items | Where-Object {($_.start -gt $startDate) -and (($_.Isrecurring -eq $false) -or ($_.isrecurring -eq $true))} 
    
    foreach($Event in $colItems){
        
        # Grabs Subject line from the event and displays it on screen later on in the code.
        $subject = $event.subject
    
      Try{
        # determines if the event from the lifesize calendar exists on the default calendar
         If($colDefault.conversationIndex -notcontains $Event.ConversationIndex){ 
        
                
                   Write-Host "Adding $subject to your calendar" -ForegroundColor Cyan  # Displays on screen what event is being added
                   $Event.ReminderSet = $true                                           # Enables the reminder
                   $Event.ReminderMinutesBeforeStart = 30                               # Sets reminder time to 30 minutes.
                   $Event.Copyto($objDefault, 2)                                        # Copies the even to the users default calendar
                   $response = $event.respond(3, $true)                                 # response parameters telling the job to accept the meeting but not send a respone.
                   $Event.Save()                                                        # Saves the event to the default calendar of the user.
    
                   Add-Content C:\Users\morellana\Desktop\Logs\InviteLog.txt -Value "$subject - has been added to your calendar" `n 
                   
           
            }# /if
         else{ Write-Host "Event $subject has already be added to your Calendar" -ForegroundColor White }# /elseif
    
       } Catch {
            
               Write-Error "Could not add LifeSize events to your Calendar" 
               
               } 
    
    
    }# /foreach
    
    
  • #20652
    Profile photo of Don Jones
    Don Jones
    Keymaster

    This might be less of a "logic" question and a "how do I actually accomplish those tasks" question?

    I mean, the logic is, "go through everything on the shared calendar, see if it exists on my calendar with the same details, and if not either create it or update it," right?

You must be logged in to reply to this topic.