-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGet-ResourceBookingOptions.ps1
80 lines (74 loc) · 3.69 KB
/
Get-ResourceBookingOptions.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<#
.SYNOPSIS
A wrapper for Get-CalendarProcessing with output focused on "Booking Options" (as shown in EXO Admin Center).
.PARAMETER Identity
Passthrough for Get-CalendarProcessing's -Identity parameter.
#>
#Requires -Version 5.1
[CmdletBinding()]
param (
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[string[]]$Identity
)
begin {
if ((Get-Command Get-CalendarProcessing, Get-Recipient -ErrorAction SilentlyContinue).Count -ne 2) {
throw 'An active Exchange PowerShell session is required, along with access to the Get-CalendarProcessing and Get-Recipient cmdlets.'
}
$Script:startTime = [datetime]::Now
$Script:stopwatchMain = [System.Diagnostics.Stopwatch]::StartNew()
$Script:stopwatchPipeline = [System.Diagnostics.Stopwatch]::new()
$Script:progress = @{
Activity = "$($PSCmdlet.MyInvocation.MyCommand.Name)"
Status = "Start time: $($startTime.ToString('yyyy-MM-ddTHH:mm:ss')) | Elapsed: $($stopWatchMain.Elapsed.ToString('hh\:mm\:ss'))"
PercentComplete = -1
}
Write-Progress @progress
$Script:ht_rcptTracker = @{}
function getRecipient ([string]$rcptId) {
if ($Script:ht_rcptTracker.ContainsKey($rcptId)) { $Script:ht_rcptTracker[$rcptId] }
else {
$rcpt = @(Get-Recipient -Filter "(Name -eq '$($rcptId)') -or (UserPrincipalName -eq '$($rcptId)') -or LegacyExchangeDNRaw -eq '$($rcptId)'" $rcptId -ErrorAction SilentlyContinue)
if ($rcpt.Count -eq 1) { $Script:ht_rcptTracker[$rcptId] = $rcpt.PrimarySmtpAddress.ToString() }
elseif ($rcpt.Count -gt 1) { $Script:ht_rcptTracker[$rcptId] = "AMBIGUOUS_ACE('$($rcptId)'):{$($rcpt.PrimarySmtpAddress -join ', ')}" }
else { $Script:ht_rcptTracker[$rcptId] = "UNKNOWN_ACE('$($rcptId)')" }
$Script:ht_rcptTracker[$rcptId]
}
}
$stopWatchPipeline.Start()
}
process {
try {
if (($PSCmdlet.MyInvocation.PipelinePosition -eq 0) -or ($stopWatchPipeline.ElapsedMilliseconds -ge 250)) {
$Script:progress.CurrentOperation = "Resource: $($Identity[0])"
$Script:progress.Status = "Start time: $($startTime.ToString('yyyy-MM-ddTHH:mm:ss')) | Elapsed: $($stopWatchMain.Elapsed.ToString('hh\:mm\:ss'))"
Write-Progress @progress
$stopWatchPipeline.Restart()
}
Get-CalendarProcessing -Identity $Identity[0] -ErrorAction Stop |
Select-Object @{Name = 'Identity'; Expression = { $Identity[0] } },
AutomateProcessing,
ForwardRequestsToDelegates,
@{
Name = 'ResourceDelegates'
Expression = { ($_.ResourceDelegates | ForEach-Object { getRecipient -rcptId $_ }) -join ', ' }
},
AllBookInPolicy, AllRequestInPolicy, AllRequestOutOfPolicy,
@{
Name = 'BookInPolicy'
Expression = { ($_.BookInPolicy | ForEach-Object { getRecipient -rcptId $_ }) -join ', ' }
},
@{
Name = 'RequestInPolicy'
Expression = { ($_.RequestInPolicy | ForEach-Object { getRecipient -rcptId $_ }) -join ', ' }
},
@{
Name = 'RequestOutOfPolicy'
Expression = { ($_.RequestOutOfPolicy | ForEach-Object { getRecipient -rcptId $_ }) -join ', ' }
},
AddAdditionalResponse, AdditionalResponse,
EnforceSchedulingHorizon, ScheduleOnlyDuringWorkHours, BookingWindowInDays, MaximumDurationInMinutes, MinimumDurationInMinutes,
AllowRecurringMeetings, AllowConflicts, ConflictPercentageAllowed, MaximumConflictInstances
}
catch { Write-Warning "Failed on Identity: $($Identity[0])"; throw }
}
end { Write-Progress @progress -Completed }