dholden36
dholden36

Reputation: 1

How to use powershell to pull out of office from exchange calendars?

I am trying to get a supervisors direct reports form AD then use that information to pull each direct reports out of office out of exchange 2013. Then mail this information everyday so the supervisor knows will be gone that day. I pulled some of this script from here and it works great on one file at a time or I am not feeding it right. Can anyone advise what I might be doing wrong and how to fix? Thanks in advance.

$users = Get-ADUser -Identity "supervisor" -Properties directreports |
Select-Object -ExpandProperty directreports |
Get-ADUser -Properties mail |
Select-Object mail

foreach ($user in $users)

{
    Add-Type -Path "C:\Program Files\Microsoft\Exchange\Web Services\2.0\Microsoft.Exchange.WebServices.dll"
    $version = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP2
    $service = new-object Microsoft.Exchange.WebServices.Data.ExchangeService($version)
    $service.UseDefaultCredentials = $true
    $service.AutodiscoverUrl($user)

    $folderid = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Calendar, $user)
    $calendarFolder = [Microsoft.Exchange.WebServices.Data.calendarFolder]::Bind($service, $folderid)
    $calendarView = new-object Microsoft.Exchange.WebServices.Data.CalendarView([System.DateTime]::Now, [System.DateTime]::Now.AddDays(2))
    $calendarView.MaxItemsReturned = 200;
    $calendarView.PropertySet = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
    $result = $calendarFolder.FindAppointments($calendarView)
}

$result | format-table

Upvotes: 0

Views: 849

Answers (1)

Dane Boulton
Dane Boulton

Reputation: 1325

If you are just looking to get the out of office state for each direct report and or the out of office message you dont need to use exhange web services. You can use the exchange management tools and use this:

get-MailboxAutoReplyConfiguration $emailAddressOrSamAccountName | select AutoReplyState,InternalMessage

This will give you the out of office state (whether the out of office message is enabled or not) and the internal out of office message set for the user. There are other properties you can grab too if you want. You can put that in your for each loop to get the status of each direct report.

Upvotes: 1

Related Questions