2
I'm building a PoSh startup script that initializes a couple scheduled tasks. One task is triggered at user logon and another is triggered on idle. Both tasks run the script again. Only the first part of the script is needed at startup, but the entire script should run all other times.
How might a script determine when it is running at startup vs running at later times?
Can't you pass a different parameter, or a different script, where the full script calls the start-up part before continuing with the remaining commands? – AFH – 2017-06-28T20:51:06.920
How often are you running the script throughout the day? – Cory Knutson – 2017-06-29T14:57:01.847
Hard to say. Idle checks every 15 minutes, but the task has a delay to run the script. The script runs shortly after logon too, so it depends on how many users. – Teknowledgist – 2017-06-29T20:42:27.167
On a Linux system I would touch a file (update the last edited date) at every run of the script. Then you can compare the uptime with the difference of the last edit time and the current time. This tells you if the last edit time was before last boot (script is run at boot) or after last boot (script is run at idle). I hope this helps you/someone to translate this idea to the Windows environment. – agtoever – 2017-07-01T06:08:46.170