Script Repository

Appoint meeting on user account expiration day

February 24, 2021

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 Exchange server that will be used to appoint meetings.

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 Adaxes service account option. If you want to use the mailbox of the Adaxes service account, specify its credentials explicitly using the This account option.

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


  • $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
$exchangeServer = "" # 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 = @("", "") # 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)
    # 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)


    $dateLargeInteger = $Context.TargetObject.Get("accountExpires")
    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))

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

Comments ( 0 )
No results found.
Leave a comment