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 (30 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 (11.0k 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.

0

Hello, thanks for writing the tutorial. We're seeing 2 errors when we attempt to implement this script.


The term 'Connect-ExchangeOnline' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. Stack trace: at {ScriptBlock}, {No file}: line 115


The term 'Set-UserPhoto' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. Stack trace: at {ScriptBlock}, {No file}: line 118


0

Hello Jordan,

What version of Adaxes are you using? For information on how to check that, have a look at the following help article: https://www.adaxes.com/help/CheckServiceVersion.

If you are using Adaxes 2020.1 or older, the errors occur because the the EXO V2 PowerShell module was not installed on the computer where Adaxes service runs.

If you are using Adaxes 2021.1, you need to use the following script from our repository: https://www.adaxes.com/script-repository/upload-user-photo-to-office-365-s327.htm.

0

We just got Adaxes about a week ago. It's 2021.1. I'll try that script, thanks!

0

I tried the first script on https://www.adaxes.com/script-repository/upload-user-photo-to-office-365-s327.htm and I think I'm doing something wrong. It seems to hang and load infinitely. What we're wanting to do is kind of a combination of this post and that post. We're wanting to have a place to browse/upload a photo that will upload a higher res image to Microsoft 365. Creating the thumbnail would be nice as well. Lastly if there is another photo already on Microsoft 365, we'd like to overwrite it. So basically we would have the abilty to update an existing image.

0

Hello Jordan,

As per your description, the first script from the repository article should be exactly what you need. It should be executed in a business rule triggering After updating a user when the corresponding property gets updated. For example: image.png If you face issues using the script, please, provide all the possible details regarding the workflow you have. If you face any error messages, please, post here or send us (support@adaxes.com) screenshots.

If you want to update multiple users in bulk, this script will not work. It will require using another approach where the script will find required user accounts and update their photos in one go.

0

That's working great! I think I was just over thinking it. Thanks!

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 (270 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 (360 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 (710 points)
0 votes
1 answer

Hi All, I have an OU ADSynced to Office 365 When I create Shared Mailboxes I basically create the user account sync it to 365 Assign it a license and and set ... only process the below actions if the previous one returned an Operation status of "Completed"

asked Oct 26, 2020 by casey101 (20 points)
0 votes
1 answer

We have several Office 365 groups where the someone is an Owner but not a Member, and we'd like to give them the ability through the web interface to give them the ability ... option in the web interface to allow them to add or remove users via a custom task?

asked Nov 1, 2023 by PaulO (20 points)
3,326 questions
3,026 answers
7,727 comments
544,678 users