0 votes

By default when you upload a user photo to Adaxes, it converts it to less than 100kb for Active Directory, that photo is synced to Azure AD, and once and only once synced to Exchange Online at 100kb. Other Office 365 apps pull the photo from Exchange. Exchange online supports higher quality photos, so I'd like to send a better quality photo there. There is a script to do that, but it calls for renaming the photo and putting it on a file share. I'd like to set our help desk up so that they don't need to use a file share for the upload. That would allow them to upload from a smartphone. There is an older script that allows you to grab the photo when it's uploaded through the web interface, unfortunately when I run that, it grabs the 100kb converted version of the photo.

What I would like, is for our help desk to upload a user photo through Adaxes, crop it, click submit. Then a business rule triggers a powershell script to grab the higher resolution version of that photo and upload to Exchange Online (Microsoft 365), back up a copy of that photo to a folder in case we need it later, and of course complete the usual conversion and upoad to local Active Directory. Is there a way to get a new version of that older script that could grab the photo before the compression to 100kb, ideally after cropping?

by (260 points)
0

Hello,

Unfortunately, there is no possibility to get the original image when updating the thumbnailPhoto attribute via Adaxes Web Interface. To achieve the desired the jpegPhoto attribute can be used. You can create a Web Interface action modifying the jpegPhoto attribute of the selected user. Then a PowerShell script executed in a Business Rule triggering After updating a user will save the image from the jpegPhoto attribute to a file, update the thumbnailPhoto attribute with the compressed (less than 100 KB) image, upload the resized to 648x648 pixels photo to Microsoft 365 and clear the jpegPhoto attribute. If the approach meets your needs, we will provide you with the script and detailed instructions.

0

Yeah, if we could have the help desk upload the photo through the web interface to trigger a process like that using jpegPhoto, that would be great.

1 Answer

+1 vote
by (3.9k points)

Hello,

Thank you for the confirmation. Below are the detailed instructions for the workflow setup.

i. Creating the Business Rule

  1. Launch Adaxes Administration Console.
  2. In the Console Tree, right-click your service node.
  3. In the context menu, navigate to New and click Business Rule. image.png
  4. On step 2 of the Create Business Rule wizard, select the User object type.
  5. Select After updating a user. image.png
  6. Click Next.
  7. Click Add an action.
  8. Select Run a program or PowerShell script.
  9. Paste the below script into the Script field. In the script, the $filePath variable specifies a template for the file path that will contain the user's photo.

Note: To use the script, install the EXO V2 PowerShell module on the computer where Adaxes service is running.

$filePath = "\\ADAXES-SUPPORT3\Share\Photo\%username%.jpg" # TODO: modify me

function ResizePhoto ($photoBytes, $maxSize, $reduceSizeStep, $reduceSizeInPercents, $maxWidth, $maxHeight)
{
    if ($reduceSizeInPercents -ge 100)
    {
        return ,$photoBytes
    }

    try
    {
        # Calculate the new size, preserve ratio
        $original = [System.Drawing.Image]$photoBytes

        $width = $original.Width
        $height = $original.Height

        if ($NULL -ne $maxWidth)
        {
            if ($width -le $maxWidth -and $height -le $maxHeight)
            {
                return ,$photoBytes
            }

            $ratioX = $maxWidth / $width
            $ratioY = $maxHeight / $height
        }
        else
        {
            $ratioX = ($width - (($width / 100) * $reduceSizeInPercents)) / $width
            $ratioY = ($height - (($height / 100) * $reduceSizeInPercents)) / $height
        }

        $ratio = $ratioY
        if ($ratioX -le $ratioY)
        {
            $ratio = $ratioX
        }

        # Resize the photo
        [int]$newWidth = $width * $ratio
        [int]$newHeight = $height * $ratio

        $newPicture = New-Object System.Drawing.Bitmap($newWidth, $newHeight)
        $graph = [System.Drawing.Graphics]::FromImage($newPicture)

        $graph.Clear([System.Drawing.Color]::White)
        $graph.DrawImage($original, 0, 0, $newWidth, $newHeight)

        $memoryStream = New-Object System.IO.MemoryStream
        $newPicture.Save($memoryStream, [System.Drawing.Imaging.ImageFormat]::Jpeg)
        $newPictureBytes = $memoryStream.ToArray()
    }
    finally
    {
        # Release resources
        if ($original) { $original.Dispose() }
        if ($graph) { $graph.Dispose() }
        if ($newPicture) { $newPicture.Dispose() }
        if ($memoryStream) { $memoryStream.Dispose() }
    }

    if (($NULL -ne $maxSize) -and 
        ($newPictureBytes.Length -gt $maxSize))
    {
        $reduceSizeInPercents += $reduceSizeStep
        $newPictureBytes = ResizePhoto $photoBytes $maxSize $reduceSizeStep $reduceSizeInPercents
    }

    return ,$newPictureBytes
}

# Get the photo
try
{
    $photoBytes = $Context.TargetObject.Get("jpegPhoto")
}
catch
{
    return # No photo
}

# Export to a file
[System.Io.File]::WriteAllBytes($filePath, $photoBytes)

# Update the thumbnailPhoto property value
$maxSize = 102400
if ($photoBytes.Length -gt $maxSize)
{
    $thumbnailPhotoBytes = ResizePhoto $photoBytes $maxSize 1 0 $NULL $NULL
}
else
{
    $thumbnailPhotoBytes = $photoBytes
}

$Context.TargetObject.Put("thumbnailPhoto", $thumbnailPhotoBytes)

# Clear the jpegPhoto property
$Context.TargetObject.Put("jpegPhoto", $NULL)
$Context.TargetObject.SetInfo()

# Upload the photo to Microsoft 365
try
{
    $objectId = [Guid]$Context.TargetObject.Get("adm-O365ObjectId")
}
catch
{
    return
}

$userPhotoBytes = ResizePhoto $photoBytes $NULL $NULL $NULL 648 648

Connect-ExchangeOnline -Credential $Context.GetOffice365Credential()

# Update the user's photo
Set-UserPhoto $objectId.ToString() -PictureData $userPhotoBytes -Confirm:$False
  1. Specify a description for the script and click OK. image.png
  2. Right-click the created action and then click Add condition. image.png
  3. Select If <property> changed.
  4. Select If JPEG Photo has changed. image.png
  5. Click OK.
  6. Right-click the created action and then click Add condition again. image.png
  7. Select If <property> <relation> <value>.
  8. Select If JPEG Photo is not empty. image.png
  9. Click OK.
  10. Click Next and finish creating the Business Rule. Finally, the rule should look like the following: image.png

ii. Creating the Web Interface action

  1. Open Adaxes Web Interface Configurator.
  2. In the top left corner, select the required Web Interface.
  3. In the Actions section, click Add. image.png
  4. Select Modify User. image.png
  5. Click Next 3 times.
  6. Select Use customized form and click Customize form. image.png
  7. Delete all sections except for one (e.g. General).
  8. Delete all properties from the remaining section.
  9. Below the Fields section, click Add. image.png
  10. Select the JPEG Photo attribute. image.png
  11. Click OK twice and finish creating the action.
  12. Save the changes.
  13. Before checking the changes, refresh the Web Interface page using Ctrl+F5.
0

Also, I think there was an issue with pasting the code into the website, it looks like the script was supposed to be in a single box, but instead it's broken into multiple boxes and headers. 

Thanks, I see whole set of instructions now.

0

This is working well. Thanks again, and can I add that I'm very impressed with Adaxes support being willing to write this new script and doing it very quickly.

Related questions

0 votes
1 answer

From my understanding I need to use a script to add send as and delegated mailbox permissions for 365 mailboxes. Does anyone have a sample script I could use for reference? Please and thank you!

asked Sep 25, 2018 by john.morrow (1.2k points)
0 votes
1 answer

Hello, I am struggling to get Adaxes to work with Office 365. I cannot get the Azure AD module installed. I have installed both the latest full version and beta ... not supported by this processor type, which is expected. OS: Windows 8 Standard 32bit SP2

asked Jan 9, 2015 by DFassett (4k points)
0 votes
1 answer

We are training our Help Desk to check for proper Office365 licensing before escalating tickets, but I cannot see where to allow "sub-licensing" views (meaning the individual ... those choices in either the Adaxes Admin Console, or the Web Portal? Thank you!

asked Jul 15, 2015 by PunkinDonuts (2k points)
0 votes
1 answer

In the de-provisioning process, I need to remove all users from all Office 365 groups (UnifiedGroups). I tried to adapt this script but unsuccessfully. https://www.adaxes.com/script-repositor ... -s360.htm Is there any way to do this?

asked Sep 22, 2019 by flaviodouglas (480 points)
0 votes
1 answer

Is there a way to use the built-in "Modify Exchange Properties" action to add a mailbox delegate that only resides in the cloud? We can do it via a powershell script, but I ... action. For example, I want to add "Company Administrator" to a user via the GUI:

asked Sep 14, 2015 by yourpp (2.5k points)
2,221 questions
1,983 answers
5,448 comments
6,566 users