0 votes

Hi

I'm having an issue saving some arrays to multivalue attributes in a scheduled task script and I cannot see what the issue is.

Import-Module ActiveDirectory
$domains = (Get-ADForest).domains

$departments = @()
$countries = @()
$companies = @()

foreach ($domain in $domains) {
    Get-ADUser -Filter * -Server $domain -Properties co, company, department, employeeid, enabled |
        Where-Object { $NULL -ne $_.employeeid -and $_.enabled -eq $true } |
        ForEach-Object {
            if ($departments -notcontains $_.department) { $departments += $_.department }
            if ($countries -notcontains $_.co) { $countries += $_.co }
            if ($companies -notcontains $_.company) { $companies += $_.company }
        }
}
$Context.TargetObject.PutEx("ADS_PROPERTY_UPDATE", "adm-CustomAttributeTextMultiValue7", $companies)
$Context.TargetObject.PutEx("ADS_PROPERTY_UPDATE", "adm-CustomAttributeTextMultiValue8", $countries)
$Context.TargetObject.PutEx("ADS_PROPERTY_UPDATE", "adm-CustomAttributeTextMultiValue9", $departments)
$Context.TargetObject.SetInfo()

The issue is that when the SetInfo is called, I get the error

Exception calling "SetInfo" with "0" argument(s): "Value cannot be null. Parameter name: value" Stack trace: at , : line 19

What I don't understand is in another script I have the same PutEx and SetInfo commands using multvalue attributes and arrays and this works perfectly. I know that the array's have values, I've added log messages to the script to check the count of each array. I've tried using a single SetInfo and commenting out all but one array and corresponding PutEx's, but the same end result.

We're running Adaxes 3.13.18001.0. Both this and the working scripts are running against single user objects (different users) on the same Adaxes server, neither user objects have been excluded from Adaxes management and both are in the same domain.

Any help will be much appreciated.

Thanks

Matt

by (5k points)

1 Answer

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

Hello Matt,

The issue occurs because at least one of the values in one of the arrays you are attempting to save to the custom multi-valued attributes is exactly $Null. You need to add a check for that to validation of the values being added to the arrays.

Also, you can use the required filter directly when calling the Get-ADUser cmdlet instead of using Where-Object. For details, have a look at the description of the -Filter and -LDAPFilter parameters in the following Microsoft article: https://docs.microsoft.com/en-us/powershell/module/addsadministration/get-aduser?view=windowsserver2019-ps.

Should you have issue updating the script, please, describe the desired behavior in all the possible details with live examples.

0

Thanks for that, works perfectly once I filtered out the null entries.

Matt

Related questions

0 votes
1 answer

Hi, we're receiving the below error when trying to add SMTP addresses to Office365 mailboxes from Adaxes. I've raised a ticket with support, but thought I'd ask ... , please see exception members for more information. Any help would be great. Thanks Gary

asked May 29, 2020 by gazoco (1.4k points)
0 votes
0 answers

Hello there, We have guest accounts created in AD (on our DMZ DC) that use the first initial + last name format for username with the last 4 digits of their mobile ... there any special way I should be updating a username and UPN from PowerShell? Thanks, Chris

asked Jul 13, 2018 by Bowman4864 (1.4k points)
0 votes
1 answer

Hi all, I want to create an external Username (username-ext). Loginname is the same as the initials. Changing the intiakls -> intials-ext ... CommandPipeline.Actions.ActionBase.Execute(ICommand command) --- Ende der internen Ausnahmestapel├╝berwachung ---

asked Jun 13, 2016 by massimo.ibba (2.5k points)
0 votes
1 answer

I am attempting to run a command using powershell. The command is using Google Apps Manager (GAM). Whenever the command runs and is successful, Powershell reports that it has ... . The issue lies with the software I am using and how it works with Powershell.

asked Nov 12, 2014 by mobosys (1.1k points)
0 votes
1 answer

Hi I've written the script below which reads the contents of a file from the network and write this to a users "adm-CustomAttributeText1" field. The code works as ... the value is not written to the attribute. Any help would be greately appreciated. Thanks

asked Feb 2, 2016 by chappers77 (5k points)
2,445 questions
2,197 answers
5,905 comments
287,868 users