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 (215k 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

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.1k 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

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)
0 votes
1 answer

I would like to know if it is possible to create a field in the web UI under user management to "assign" a machine to a user. I would like to be able to put the ... be moved to "workstation OU. Is there s custome field that can be used to accomplish this?

asked Oct 22, 2020 by copatterson (70 points)
0 votes
1 answer

Hello, I'd like setup a new custom command on the Administrator dashboard that would run the following tasks against a disabled user account simultaneously. Enable their account ... the email when using the %unicodePwd% value. Is there a workaround for this?

asked Apr 23, 2020 by sirslimjim (430 points)
2,801 questions
2,535 answers
6,605 comments
61,759 users