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

Is it possible to have a business rule of the form: IF (company = "Company1") then set City = "New York" set Manager = "New York Manager" If (state = "CO") then set telephone "303" else if (state = "NY") set telephone "202" else clear telephone end if end if

asked Aug 23 by Jiver (20 points)
0 votes
1 answer

I am noticing a large amount of PowerShell Transcript files in the Adaxes SA accounts Documents folder. These are different than the logging feature which has a very ... Can I configure these transcripts in any way to manage their space consumption/retention?

asked Nov 5 by SysADM (50 points)
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

For creating a computer object, we want to check if the entered CN is already used in our AD. And for that we want to use a powershell script. An other dot ... powershell script should be start before creating the computer object, right? Thanks for your help.

asked Jun 4 by KEME (80 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)
3,538 questions
3,229 answers
8,222 comments
547,739 users