Announcement

Collapse
No announcement yet.

EWS - Office 365 - Extract Room Calendar Info with PowerShell

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • EWS - Office 365 - Extract Room Calendar Info with PowerShell

    I've been given what I thought to be a simple job. It's turning out to be nightmarish and convoluted.

    We have a meeting room which has an Office 365 Room Calendar associated with it. I need to extract the following info:

    From today, to seven days from now, list all meetings that will take place in that room including:

    - Date
    - Start and end times of meeting
    - Subject

    A CSV output file would be perfect.

    I did the usual Google searches and came up with a lot of Powershell scripts including this excellent post here that uses EWS:

    http://gsexdev.blogspot.com/2015/03/...ile-using.html

    Script works brilliantly, but the problem is, this script only works with user calendars and not room calendars. I also need to set this up to run autonomously several times a day to update the info as it will drive a Rasp Pi with a small display outside of the meeting room.

    I don't have the chops to write my own script without a lot more info. Can any of you assist with examples?

    Thanks.

  • #2
    This should probably help and then you should be able to merge both into one.

    https://social.msdn.microsoft.com/Fo...svrdevelopment

    Code:
     
                 DateTime StartDate = DateTime.Today;             DateTime EndDate = DateTime.Today.AddMonths(2);             CalendarView cv = new CalendarView(StartDate, EndDate);             String MailboxToAccess = "[email protected]";             FolderId CalendarFolderId = new FolderId(WellKnownFolderName.Calendar, MailboxToAccess);             FindItemsResults<Appointment> fapts = service.FindAppointments(CalendarFolderId, cv);             if (fapts.Items.Count > 0)             {                 foreach (Appointment Appoint in fapts)                 {                     Console.WriteLine(Appoint.Start);                     Console.WriteLine(Appoint.Subject);                 }             }

    Comment


    • #3
      Morning,

      I had great success with the original script in my original post. It runs brilliantly when I run it and type credentials in. However, I cannot get the creds to be cached so it can be run automatically.

      I hashed out the following in the script:

      Code:
      #Credentials Option 1 using UPN for the windows Account  
      #$psCred = Get-Credential  
      #$creds = New-Object System.Net.NetworkCredential($psCred.UserName.ToString(),$psCred.GetNetworkCredential().password.ToString())  
      #$service.Credentials = $creds      
      #Credentials Option 2  
      #service.UseDefaultCredentials = $true
      and replaced it with code I found on another blog page:
      Code:
      $username = "[email protected]"
      $pwdTxt = Get-Content "C:\CSV\ExportedPassword.txt"     (This is an exported password txt file)
      $securePwd = $pwdTxt | ConvertTo-SecureString
      $credObject = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $securePwd
      When I run the script I get:
      Code:
      Exception calling "Bind" with "2" argument(s): "The request failed. The remote server returned an error: (401)
      Unauthorized."
      At C:\CSV\CalDumpCSV.ps1:94 char:1
      + $Calendar = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderi ...
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
      + FullyQualifiedErrorId : ServiceRequestException
      
      Exception calling "FindAppointments" with "2" argument(s): "The element at position 0 is invalid
      Parameter name: parentFolderIds"
      At C:\CSV\CalDumpCSV.ps1:111 char:1
      + $fiItems = $service.FindAppointments($Calendar.Id,$CalendarVi ew)
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~
      + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
      + FullyQualifiedErrorId : ArgumentException

      Why Microsoft make this so idiotically difficult is beyond me. I have tried many different blog / technet solutions to do this and none work without error.
      Last edited by shadragon; 17th April 2017, 15:31.

      Comment


      • #4
        Write your credentials to an XML file and read that way. It will save them as encrypted.

        Get-Credential [email protected] | Export-Clixml $env:USERPROFILE\Documents\Office365.xml

        Remember that this will fill NOT be read on any other machine than the one it was created on.

        Comment


        • #5
          Hi wullieb1,

          This is the verbatim result of that command, save the x'd out email. I see no password hash.

          Code:
          <Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04">
            <Obj RefId="0">
              <TN RefId="0">
                <T>System.Management.Automation.PSCredential</T>
                <T>System.Object</T>
              </TN>
              <ToString>System.Management.Automation.PSCredential</ToString>
              <Props>
                <S N="UserName">[email protected]</S>
                <S N="Password">System.Security.SecureString</S>
              </Props>
            </Obj>
          </Objs>

          Comment


          • #6
            You're doing something incorrect then.
            I've just ran it on my home system using my 365 logon credentials and i get the following

            Code:
            <Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04">
              <Obj RefId="0">
                <TN RefId="0">
                  <T>System.Management.Automation.PSCredential</T>
                  <T>System.Object</T>
                </TN>
                <ToString>System.Management.Automation.PSCredential</ToString>
                <Props>
                  <S N="UserName">[email protected]</S>
                  <SS N="Password">01000000d08c9ddf0115d1118c7a00c04fc297eb010000009f42c30849db0345906fb5fb6ccb5c65000000000200000000001066000000010000200000004d003a21f970bab99015b2adf3ea16ad6ee8ddc81f22a47c918000dd2fe3e838000000000e80000000020000200000001caf6186a2601cae0ed0d2017d9d57cb833c95676b8309ca9e2aaf7fc9c1e85f2000000001d4976d06a4c91456d425eb5796e517dd29869b697328a9c33ea67e43593acb40000000e5c8458626d390bec64be5274d6fb98a696fa0f6efe43406ffef7bf8a746c9543e142a0dd5f06c49f847cb2e39846e5f80ee8a9f574766a29aa0d92eaafa7578</SS>
                </Props>
              </Obj>
            </Objs>

            Comment

            Working...
            X