-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSet-BulkMailboxAutoReply.ps1
More file actions
78 lines (65 loc) · 2.35 KB
/
Copy pathSet-BulkMailboxAutoReply.ps1
File metadata and controls
78 lines (65 loc) · 2.35 KB
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
<#
.SYNOPSIS
Bulk-enable Exchange Online automatic replies (OOO) for multiple mailboxes from a CSV mapping file.
.DESCRIPTION
Reads a CSV with mailbox + internal/external message content, applies Set-MailboxAutoReplyConfiguration,
and writes a results log CSV.
PREREQS
- ExchangeOnlineManagement module
- Connected session to Exchange Online (Connect-ExchangeOnline)
#>
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[Parameter(Mandatory)]
[ValidateScript({ Test-Path $_ })]
[string]$CsvPath,
[Parameter()]
[ValidateSet('All','Known','None')]
[string]$ExternalAudience = 'All',
[Parameter()]
[ValidateScript({ Test-Path $_ -PathType Container })]
[string]$LogDirectory = $env:TEMP
)
function Assert-ExchangeConnected {
if (-not (Get-Command Set-MailboxAutoReplyConfiguration -ErrorAction SilentlyContinue)) {
throw "Set-MailboxAutoReplyConfiguration not found. Connect to Exchange Online and/or install ExchangeOnlineManagement."
}
}
Assert-ExchangeConnected
$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
$logPath = Join-Path $LogDirectory "OOO_SetResults_$timestamp.csv"
$items = Import-Csv -Path $CsvPath
$results = @()
foreach ($row in $items) {
$mailbox = $row.Mailbox
$internal = $row.InternalMessage
$external = if ([string]::IsNullOrWhiteSpace($row.ExternalMessage)) { $internal } else { $row.ExternalMessage }
if ($PSCmdlet.ShouldProcess($mailbox, "Enable OOO and set internal/external messages")) {
try {
Set-MailboxAutoReplyConfiguration `
-Identity $mailbox `
-AutoReplyState Enabled `
-ExternalAudience $ExternalAudience `
-InternalMessage $internal `
-ExternalMessage $external `
-ErrorAction Stop
$results += [pscustomobject]@{
Mailbox = $mailbox
Status = "Success"
When = Get-Date
Notes = ""
}
}
catch {
$results += [pscustomobject]@{
Mailbox = $mailbox
Status = "Failed"
When = Get-Date
Notes = $_.Exception.Message
}
}
}
}
$results | Export-Csv -NoTypeInformation -Path $logPath
Write-Output "Done. Log saved to: $logPath"
$results | Sort-Object Status,Mailbox