Public/Set-MassOutOfOffice.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
function Set-MassOutOfOffice
{
    <#
    .SYNOPSIS
    Permanently removes deleted MSOL users.
     
    .DESCRIPTION
    Permanently removes accounts using the -Force switch.
     
    .EXAMPLE
    Remove-DeletedUsers
    #>

    [CmdletBinding()]
    Param
    (
        [parameter(mandatory=$True,position=0)]
        [String]
        $Users,
        [parameter(mandatory=$True,position=1)]
        [String]
        $ExternalMessage,
        [parameter(mandatory=$True,position=2)]
        [String]
        $InternalMessage
    )
   
    foreach ($User in $Users)
    {
        try
        {
            Set-MailboxAutoReplyConfiguration -Identity $($User.Mailbox) -AutoReplyState Enabled -ExternalMessage $ExternalMessage -InternalMessage $InternalMessage
            Write-Host "Set out of office messages for user $User"
            Write-Output "Set out of office messages for user $User" | Out-File MassOutOfOffice.log -Append
        }
        catch
        {
            Write-Error "An error has occured setting the out of office message for user $User"
            Write-Error "An error has occured setting the out of office message for user $User" | Out-File MassOutOfOffice.log -Append
        }
    }

}