使用Exchange Web服务在会议上花费的时间

时间:2018-08-06 16:10:10

标签: c# powershell exchange-server exchangewebservices managed-ews

我正试图找出我们作为一个部门在会议上所花费的时间(约100人)。为简单起见,我们可以将所有繁忙时间都视为会议中的繁忙时间。但是我不知道该怎么做,我希望有人有主意

1 个答案:

答案 0 :(得分:0)

您需要显示尝试过的代码以及遇到的错误(如果有)。但是,仍有一些示例在整个Web上使用EWS API进行此类操作。对于

示例示例供您使用:

使用EWS托管API获取约会 以下代码示例演示如何使用EWS托管API检索介于指定开始时间和结束时间之间的用户约会。

// Initialize values for the start and end times, and the number of appointments to retrieve.
            DateTime startDate = DateTime.Now;
            DateTime endDate = startDate.AddDays(30);
            const int NUM_APPTS = 5;
            // Initialize the calendar folder object with only the folder ID. 
            CalendarFolder calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet());
            // Set the start and end time and number of appointments to retrieve.
            CalendarView cView = new CalendarView(startDate, endDate, NUM_APPTS);
            // Limit the properties returned to the appointment's subject, start time, and end time.
            cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End);
            // Retrieve a collection of appointments by using the calendar view.
            FindItemsResults<Appointment> appointments = calendar.FindAppointments(cView);
            Console.WriteLine("\nThe first " + NUM_APPTS + " appointments on your calendar from " + startDate.Date.ToShortDateString() + 
                              " to " + endDate.Date.ToShortDateString() + " are: \n");

            foreach (Appointment a in appointments)
            {
                Console.Write("Subject: " + a.Subject.ToString() + " ");
                Console.Write("Start: " + a.Start.ToString() + " ");
                Console.Write("End: " + a.End.ToString());
                Console.WriteLine();
            }

https://docs.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-get-appointments-and-meetings-by-using-ews-in-exchange

基本Powershell脚本,使用EWS托管API显示日历中的约会

$MailboxName = 'SomeUserEmailALias'

$StartDate = Get-Date
$EndDate = (Get-Date).AddDays(7)

$DllPath = 'C:\Program Files\Microsoft\Exchange\Web Services\1.2\Microsoft.Exchange.WebServices.dll'
[void][Reflection.Assembly]::LoadFile($DllPath)
$Service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010)
$Service.AutodiscoverUrl($MailboxName)

$FolderID = New-Object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Calendar,$MailboxName)

$CalendarFolder = [Microsoft.Exchange.WebServices.Data.CalendarFolder]::Bind($Service,$FolderID)
$Calendarview.PropertySet = New-Object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
$CalendarResult = $CalendarFolder.FindAppointments($CalendarView)

foreach ($Appointment in $CalendarResult.Items)
{
    $Propset = New-Object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)

    $Appointment.load($Propset)

    New-Object -TypeName PSObject -Property @{
            Appointment = $Appointment.Subject.ToString()
            Start = $Appointment.Start.ToString()
            End = $Appointment.End.ToString()
            Organizer = $Appointment.Organizer.ToString()
        }
}

https://gsexdev.blogspot.com/2009/11/basic-powershell-script-to-show.html

[Powershell脚本EWS]使用EWS托管API处理日历项

$Folderid= new-object Microsoft.Exchange.WebServices.Data.FolderId `

([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Calendar,$MailboxToImpersonate) 
$cal=[Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$Folderid)

$StartDate =(Get-Date)

$EndDate =(get-date).AddDays(7)
$CalendarView = New-Object Microsoft.Exchange.WebServices.Data.CalendarView `
($StartDate,$EndDate,$itemsView)
$findCalItems = $service.FindAppointments($Cal.Id,$CalendarView)

param
(
    $mailbox="SomeUserEmailALias",
    $itemsView=1000,
    $userName=$cred.UserName,
    $password=$cred.GetNetworkCredential().password,
    $StartDate =(Get-Date),
    $EndDate =(get-date).AddDays(7) # find meeting upto next 7 days.
)
#set EWS URL and Web Service DLL file location path below.
$uri=[system.URI] "https://outlook.office365.com/ews/exchange.asmx"
$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll"
Import-Module $dllpath

#Set Exchange Version
$ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP2
$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService($ExchangeVersion)
$service.Credentials = New-Object Microsoft.Exchange.WebServices.Data.WebCredentials -ArgumentList $userName, $password
$service.url = $uri

$service.ImpersonatedUserId = New-Object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId `
([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SMTPAddress,$mailbox);

$Folderid= new-object Microsoft.Exchange.WebServices.Data.FolderId `
([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Calendar,$mailbox)
$cal=[Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$Folderid)

#Define the calendar view
$CalendarView = New-Object Microsoft.Exchange.WebServices.Data.CalendarView($StartDate,$EndDate,$itemsView)    
$findCalItems = $service.FindAppointments($Cal.Id,$CalendarView)

$report = $findCalItems | Select Start,End,Duration,AppointmentType,Subject,Location,
Organizer,DisplayTo,DisplayCC,HasAttachments,IsReminderSet,ReminderDueBy

$report | Export-Csv $($mailbox + "-Meetings.csv") -NoTypeInformation

https://www.linkedin.com/pulse/powershell-script-ews-working-calendar-items-using-managed-chauhan

用于将日历信息导出到CSV文件的EWS脚本。

.Synopsis:

Script which creates a function "Export-CalendarInformation" which can be used to export details of each calendar items to a CSV file.



. Description:

Using EWS API and authorized credentials (can use an account with application impersonation permission) this script exports below details of each calendar item in a mailbox calendar to CSV file. This script will return



StartTime, EndTime, Duration, Type, Subject, Location, Organizer, Attendees, AppointmentState, Notes, HasAttachments, IsReminderSet

https://gallery.technet.microsoft.com/EWS-Script-to-Export-c76a0ad4