Script Repository


Appoint meeting on user account expiration day

July 07, 2017
1075

The script appoints a meeting that will be scheduled for the expiration date of a user account. To appoint such automatically, you can create a Business Rule triggered when the account expiration date is modified.

To be able to use the script, download and install Microsoft Exchange Web Services Managed API on the computer where Adaxes service runs.

The meetings will be created in the calendar of the user specified in the Run As section of the Run a program or PowerShell script action used to run the script. Make sure that the user has an Exchange mailbox.

Warning: The script cannot be used with the Default service administrator option. If you want to use the mailbox of the default service administrator, specify it explicitly using the This account option.

Additional meeting invitations will be sent to mailboxes and/or mail-enabled groups specified in the script.

Parameters:

  • $exchangeServer - specifies the fully qualified domain name (FQDN) of your Exchange Server;
  • $exchangeWebServiceDllPath - specifies the full path to the Microsoft Exchange Web Services dll module;
  • $subject - specifies the appointment notification message subject;
  • $bodyText - specifies the appointment notification message text;
  • $attendeesMailAddresses - specifies email addresses of additional attendees who will receive the meeting invitation.
See Also: Set account expiration date via meeting in Exchange.
Edit Remove
PowerShell
$exchangeServer = "exchangeserver.example.com" # TODO: modify me
$exchangeWebServiceDllPath = "C:\Program Files\Microsoft\Exchange\Web Services\2.0\Microsoft.Exchange.WebServices.dll" # TODO: modify me

# Appointment settings
$subject = "My Appointment" # TODO: modify me
$bodyText = "My Appointment Description" # TODO: modify me
$attendeesMailAddresses = @("john.doe@example.com", "mailgroup@example.com") # TODO: modify me

$scriptBlock = {
    Param($exchangeWebServiceDllPath, $credentials, $subject, $bodyText, $date, $attendeesMailAddresses)
    
    Import-Module $exchangeWebServiceDllPath
        
    $exchangeWebService = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService
    $exchangeWebService.Credentials = New-Object System.Net.NetworkCredential($credentials.Username, $credentials.password)
    $exchangeWebService.AutodiscoverUrl("%mail%")
    
    # Create new appointment
    $appointment = New-Object Microsoft.Exchange.WebServices.Data.Appointment -ArgumentList $exchangeWebService
    $appointment.Subject = $subject
    $appointment.Body = $bodyText
    $startDate = New-Object "System.Datetime" $date.Year, $date.Month, $date.Day
    $appointment.Start = $startDate
    $appointment.End = $startDate.AddDays(1)
    $appointment.IsAllDayEvent = $True
    
    foreach ($mailAddress in $attendeesMailAddresses)
    {
        [void]$appointment.RequiredAttendees.Add($mailAddress)
    }

    $appointment.Save([Microsoft.Exchange.WebServices.Data.SendInvitationsMode]::SendOnlyToAll)
}

try
{
    $dateLargeInteger = $Context.TargetObject.Get("accountExpires")
}
catch
{
    return # Account expiration date not set
}

if (($dateLargeInteger -eq 0) -or ($dateLargeInteger -eq 9223372036854775807))
{
    return # Account never expires
}

# Convert to DateTime
$date = [DateTime]::FromFiletime([Int64]::Parse($dateLargeInteger))

try
{
    # Execute script block on the Exchange Server
    $result = Invoke-Command -ScriptBlock $scriptBlock -ArgumentList $exchangeWebServiceDllPath, $Context.RunAs, $subject, $bodyText, $date, $attendeesMailAddresses -ComputerName $exchangeServer -ErrorAction Stop
}
catch
{
    $Context.LogMessage($_.Exception.Message, "Warning")
}


Comments ( 0 )
No results found.
Leave a comment