Some PowerShell Foo...playin' with da Task Scheduler
When adopting something new it can take quite a while until you really get into it. PowerShell is such a thing. When it came out I played around with it, not more. Now, with us having to provide some maintenance tools for our last project and me working on connecting Powershell to MSBuild, things look different. PowerShell feels like a Swiss army knife.
Just today we had an update issue on our Continuous Integration server. There are several tasks running via the Task Scheduler. When they run, the respective dlls cannot be updated. One way to solve this is to ensure that during the nightly build no task is running.
Powershell to the rescue.
Let’s get access to the Task Scheduler API and connect to the local Task Scheduler Service:
Our tasks are located at the root and follow a certain name pattern
Tasks are obviously objects with properties and methods, hence we may want to look at their names
Now, we can disable them.
Or we actually want to figure out if any task is currently running:
Pack this all in and kick it off as a task and presto, you can disable and enable registered tasks without much hassle.
Second work site today: Administering the DB behind my website. With the SQLServer Commandlets one can very quickly create functions that are tailored to certain things:
and then for example
Sometimes it’s good to have an army knife.