0 votes

Hello

We are using the script you created for us to upload the employees photo based on their employee ID which works fantastic. The script is below:

$picturePath = "picture path"  # TODO: modify me
# Check whether a file with the photo exists
if(!(Test-Path -Path $picturePath))
{
    $Context.LogMessage("The path to the user's picture is incorect.", "Error") # TODO: modify me
    return
}

# Save picture to AD
[Byte[]]$pictureInByte = Get-Content $picturePath -Encoding Byte
$Context.TargetObject.Put("thumbnailPhoto", $pictureInByte)
$Context.TargetObject.SetInfo()

As we only want to add a photo if there is not one at the moment and then add the user to a group we currently use it in a custom command that has the following actions:

If the 'thumbnailPhoto' property is empty then
Run PowerShell script 'Import Photo' for the user
Add the User to the 'AD Group Name' group

We have run into issues recently where the user does not have a photo loaded but there in not a photo in the location to load, we get the error message but they way we have it the user is still added to the 'AD Group Name'. We would like to amend this so if there is no photo loaded they are not added to the group. If there is a photo uploaded they would still be added to the group.

Could you help out please? I feel like I am missing something obvious but can't see how to do it :?

Thank you.

by (700 points)

1 Answer

0 votes
by (216k points)
selected by
Best answer

Hello,

In this scenario, it is better to add users to the group directly in the script. Here's a version of the script that will do the job. In the script, $groupDN specifies the Distinguished Name (DN) of the group a user must be added to if the picture has been imported correctly.

$picturePath = "\\SERVER\Share\%username%.jpg" # TODO: modify me
$groupDN = "CN=Import Photo,CN=Users,DC=example,DC=com" # TODO: modify me

# Check whether a file with the photo exists
if(!(Test-Path -Path $picturePath))
{
    $Context.LogMessage("The path to the user's picture is incorect.", "Error") # TODO: modify me
    return
}

# Save picture to AD
[Byte[]]$pictureInByte = Get-Content $picturePath -Encoding Byte
$Context.TargetObject.Put("thumbnailPhoto", $pictureInByte)
$Context.TargetObject.SetInfo()

# Add the user to the group
$group = $Context.BindToObjectByDN($groupDN)
$group.Add($Context.TargetObject.AdsPath)
0

Thank you this works perfectly.

Related questions

0 votes
1 answer

Hi team, I have a follow up to this question https://www.adaxes.com/questions/14234/business-after-adding-members-powershell-script-executed Let me explain my setup A rule- ... area% failed due to the following exception: $($_.Exception.Message)", "Error") }

asked Feb 13 by wintec01 (1.1k points)
0 votes
1 answer

I would like to add a parameter for country to a custom command. Since the country has to be entered correctly in order for Active Directory to accept it, I would like to ... ? I didn't find it in the documentation and the sample scripts didn't use parameters.

asked Jun 4, 2020 by mark.it.admin (2.3k points)
0 votes
1 answer

As the title says, Im looking to add a Custom Command to the Action pane that I plan to allow users to trigger a script to run. However when in the Web Config for ... as has the permissions to make changes to the Web Inferface. Am I missing something? Thanks

asked Jul 16, 2019 by Helios5287 (100 points)
0 votes
1 answer

We have a business rule that will update an AD attribute when a new member is added to a group. This business rule works when we use powershell commands or the admin console ... set to trigger "After adding a member to a group". Thank you for your support!

asked Mar 29, 2023 by mark.it.admin (2.3k points)
0 votes
1 answer

Is there a way to get the name of the user who approved a request and supply that to a step inside of a custom command? For example, HR submits a status change for an employee. ... and pass it as a param in a custom command that is called in one of the steps?

asked May 12, 2021 by davfount90 (20 points)
3,347 questions
3,048 answers
7,788 comments
545,036 users