This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to include search object in an email?

 Hi guys,

I'm attempting to build a workflow that will look for a virtual attribute set to a date/time. The workflow will compare the time to the current time, and send an email once the time is older than current time.

My issue is that I can't seem to get the email to include the name of the object found by the search. How can I go about doing this? Basically it's to send out a notification for a user departure. Typically I'd use this:

<% =Operation.TargetObjectDisplayName %>

But that does not seem to work, as it isn't technically the target. Is what I'm trying to do possible? There are a few different variables I'm trying to pull from the AD object, but Display Name would be a good start

  • So far I've been unable to find a way to do this natively in the workflow. I did manage to work it into a powershell script, hopefully this scales ok.

    For anyone looking in the future, here's what I did:


    function Notify ($request)
            $NotifiedUser = ""
            $dn = $workflow.FoundObject("DepartSearch").get("distinguishedName")
            $displayname = Get-QADUSer $dn -properties cn | select -expandproperty cn
            $departureTime = Get-QADUser $dn -includedproperties edsva-LastDateinOffice | Select -expandproperty edsva-LastDateinOffice
            $buildingcutoff = Get-QADUser $dn -includedproperties edsva-BuildingAccessTerminationTime | Select -expandproperty edsva-BuildingAccessTerminationTime
            $departdatetime = Get-QADUser $dn -includedproperties edsva-DepartureDateTime | Select -expandproperty edsva-DepartureDateTime
            $office = ""
            try{$office = get-qaduser $dn -properties extensionAttribute15 | select -expandproperty extensionAttribute15}
            $emailbody = 
            "<p><p>Hi Everyone,</p> 
            <p>Please note that <b>$departureTime</b> is the last day in the $office office for $displayname</p>
            Facilities, please terminate all building access as of <b>$buildingcutoff</b>
            <p>Thank You!</p></p>"
            Send-MailMessage -SmtpServer "" `
                             -To $notifieduser `
                             -From "" `
                             -Subject "[HOLD] Departure Notification, $displayname - $departdatetime" `
                             -BodyAsHTML "$emailbody"

  • Thanks for sharing this.

    Can I suggest the following to cut down on the number of Get-QADUser calls...

    $UserDetails = Get-QADUSer -identity $dn -proxy -IncludedProperties edsva-LastDateinOffice,edsva-BuildingAccessTerminationTime,edsva-DepartureDateTime

    # Name and cn are the same thing
    $displayname = $
    $departureTime = $UserDetails.'edsva-LastDateinOffice'
    $buildingcutoff = $UserDetails.'edsva-BuildingAccessTerminationTime'
    $departdatetime = $UserDetails.'edsva-DepartureDateTime'
  • thanks for example, Anthony! The most tricky part here is how to process in-process Workflow variable.
    $dn = $workflow.FoundObject("DepartSearch").get("distinguishedName")
  • Ah, thanks! That definitely helps lower clutter. I'll probably switch it over to something like this to keep it a bit cleaner.

    I'm not the best with PS, slowly improving though :P