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

Most of my PowerShell code is written in VS Code and then copied/pasted to the Adaxes script editor. However, if you use $Context in your scripts, you can't execute them ... = [Context]::new() $Context.LogMessage("foo", "information") Output: [Information] foo

asked Nov 3, 2023 by ngb (220 points)
0 votes
1 answer

I often need to step through a script in the ISE debugger to troubleshoot or verify its operation. My problem is that I haven't been able to find a way to do ... way to interactively run a script uses the $Context variable so you can step through/debug it?

asked Dec 18, 2016 by rbeu (100 points)
0 votes
1 answer

I'm trying to modify this report to only output results where employeeType equals the values below. It reports fine. I would also like to include where employeeType ... = "(&amp;" + $filterUsers + $filterPasswordLastSet + $customAttribute + $enabledUser + ")"

asked 23 hours ago by tromanko (180 points)
3,326 questions
3,026 answers
7,727 comments
544,678 users