0 votes

Can I get some help with a PowerShell if statement? I'm looking to write something like If the script/custom command is fired via a scheduled task do this. If/Else the script/custom command is fired manually against a user do this.

I was thinking I could do something like this but I'm getting an error that TaskName property cannot be found in the cache when running the custom command against a user.

if ($Context.Initiator.UserAdsObject.Get("TaskName") -eq "My Scheduled Task") {"Do Something"} Else {Do Something Different"}

Thanks!
Ryan

by (920 points)

1 Answer

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

Hello Ryan,

This can be done using the If the initiator is <User> condition in your Custom Command. No PowerShell scripts are required. In the condition, you will need to use the distinguished name (DN) of the Scheduled Task. For information on how to get the DN, see https://www.adaxes.com/sdk/?HowDoI.GetDnOfObject.html.

Finally, the Custom Command will look like the following:

Related questions

0 votes
1 answer

Hi, we just recently installed Adaxes and would like to implement a PowerShell script that I have previously written which cleans up user objects if they have been manually ... to perform the operation Stack trace: at &lt;ScriptBlock&gt;, &lt;No file&gt;".

asked Oct 2, 2023 by Mark.Monaco (20 points)
0 votes
1 answer

Hi Using 2018.1 (3.9.15631.0) I'm not sure if this is an issue as such, or if it is a known thing with the Adaxes powershell commands but when using the Move-AdmObject command within a Try statement, if the command fails the error is not caught. Thanks

asked Aug 10, 2018 by chappers77 (2.0k points)
0 votes
1 answer

Can anyone provide the instructions contain in the now broken link? I realize new Adaxes doesn't require this, but still have an older install that doesn't allow manual override via GUI. Thanks.

asked Oct 13, 2022 by okiad (20 points)
0 votes
1 answer

We have password self-service enabled with users adding their questions, but was wondering if we could dispaly those answers to the help desk so that they can confirm that the user calling in is actually them? Is there an option to do somnething like that?

asked Mar 16, 2022 by seannicholas71 (20 points)
0 votes
0 answers

I am creating a new scheduled task and form. We would like to have the ability to schedule the reassignment of a staff member to a different location in the future. ... context, my manager won't necessarily know when he tries to move somebody. Thanks everybody

asked May 21, 2020 by jcalvert (60 points)
3,326 questions
3,025 answers
7,723 comments
544,675 users