0 votes

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 expected up to the point where I use the SetInfo when nothing is actually written to the users object.

#Read the message from the text file
$File = "path to file.txt"
[string]$Tip = Get-Content $File

#Check the message is short enough, truncate and warn the user if it isn't. Set the message it if is.
if ($Tip.Length -gt 175) {

    $Temp = "You can only use 175 characters for this message. Your message has been truncated as follows, please remove this line, edit and save your message again.`r`n" + $Tip.SubString(0, 175)
    Set-Content -Path $File -Value $Temp
} Else {

    $Context.TargetObject.Put("%adm-CustomAttributeText1%",$Tip)
    $Context.TargetObject.SetInfo
}

I know that the Put is working, because of I add the following line to the script after the put, I get the value back:

Set-Content -Path "Path to another file.txt" -Value $Context.TargetObject.Get("%adm-CustomAttributeText1%") 

If I use brackets after the SetInfo (as per the examples) then I just get a message 'Exception calling "SetInfo" with "0" argument(s).'
If I try putting the attribute name (or anything else) in the brackets then I get an error that there is no overload for a single argument.
Without the brackets the script seems to be happy and runs, but the value is not written to the attribute.

Any help would be greately appreciated.

Thanks

by (2.0k points)
0

I should have specified, this is running inside an Adaxes Custom Command.
The script is running as a domain admin account.

1 Answer

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

Hello,

The thing is that SetInfo is a method, not a property. According to PowerShell syntax, when calling a method, you need to use parenthesis.

Also, as the 1st parameter of the Put method, you need to pass the name of a property whose value you want to set, however %adm-CustomAttributeText1% will return you the value of the adm-CustomAttributeText1 attribute. To pass the attribute name, remove the percent characters ('%').

Somthing like this should resolve your issue:

<i class="text-italic">...
    $Context.TargetObject.Put("<strong class="text-bold"><span class="color" style="color: #008000;">adm-CustomAttributeText1</span></strong>", $Tip)
    $Context.TargetObject.SetInfo<strong class="text-bold"><span class="color" style="color: #008000;">()</span></strong>
}</i>
0

Hi

That's worked, thanks very much.

Matt

Related questions

0 votes
1 answer

I have a 'Before user account creation' business rule that starts as follows: If script 'Validate user exists' returns true then Do Nothing // rest of ... experiencing a bug where $Context.Cancel is not properly terminating the business rule. Thanks.

asked Dec 17 by lw.fa (150 points)
0 votes
1 answer

I am trying to send a $context.logmessage from a condition script in a Scheduled Task but I get nothing in the log. Is this not possible? Morten A. Steien

asked Jul 20, 2020 by Morten A. Steien (300 points)
0 votes
1 answer

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 ... and both are in the same domain. Any help will be much appreciated. Thanks Matt

asked Mar 25, 2021 by chappers77 (2.0k points)
0 votes
1 answer

If I have a scheduled task powershell script that's targeting an OU of users and in that script I were to call $context.cancel in the case of an error happening for a single ... it cancel the entire scheduled tasks and it won't run for other users in that OU?

asked Oct 18 by wrichardson (20 points)
0 votes
1 answer

Hi, we're trying to map certain actions to business rules, is there anyway to see the action in a more readable way? Adding a user to a group seems to show the following: { ... to dump the entire content of "$context" so that I can see what might be usable?

asked Jul 29 by ZoomGhost (280 points)
3,589 questions
3,278 answers
8,303 comments
548,137 users