So to give you some background – i’ve never had to get the User ID for a scheduled task. I got interested when I saw your post and went through the inspector guide to figure it out.
It can be hard to explain relevance like this but here we go!
Relevance is object oriented so to do anything we need to create an object. To do this we use creation methods.
The creation method for scheduled tasks is, “Scheduled Tasks” (defined here): http://support.bigfix.com/inspectors/Task%20Objects_Any.html#scheduled task
If we run this in Fixlet debugger we get the following:
Q: scheduled tasks
E: This expression evaluates to an unrepresentable object of type "scheduled task"
T: 171.249 ms
This is a good error. This means that we have a list of scheduled tasks but it doesn’t know how to show us what a scheduled task looks like.
So how do we represent a scheduled task? A name works. If we look at the guide we see under, “Properties” that there is a name of . Lets give that a shot.
Q: names of scheduled tasks
A: Optimize Start Menu Cache Files-S-1-5-21-1440172557-2372731197-1498938429-1104
A: Optimize Start Menu Cache Files-S-1-5-21-2832046585-3437359362-1061037012-1001
A: Optimize Start Menu Cache Files-S-1-5-21-2832046585-3437359362-1061037012-500
A: Optimize Start Menu Cache Files-S-1-5-21-2907966901-224744048-3677943571-1103
A: .NET Framework NGEN v4.0.30319
T: 172.375 ms
Cool! Now we have the names of all the tasks. Now onto the real goal – lets get the user the task will run as.
My first instinct… search the inspector page for, “User” and find, "user id of "
This could work except that we have objects of type, “Scheduled Task” not, “Task principal” so we need to somehow turn, “Scheduled Task” into “Task Principal” so we can get the user ID of it.
So we find the Task Principal object in the inspector guide and see its creation method: "principal of ". This will give us a Task Principal object from a task definition object.
Ok… well that’s closer – but we still have the same issue, we have a Scheduled Task object not a task definition object.
So lets look at the task definition object!
Here we find a creation method: "definition of ". This will give us a task definition object from a scheduled task object.
Now we can combine them all together:
Definition of (Scheduled Tasks)
Principals of (Definitions of (Scheduled Tasks))
User IDs of (principals of (definitions of (scheduled tasks)))