Performing Maintenance in Task Sequences

Using the scheduling tools available to you in ConfigMgr is a great way to perform weekly, monthly or even annual maintenance on your clients to ensure they operate at peak performance. This post looks at creating and deploying a task sequence to enable maintenance to take place.

So the scenario is as follows. We already patch our machines with all available patches on a monthly basis, we run this every last Friday of the month. The problem is we also want to perform other maintenance jobs on clients but getting the approval from management is difficult. We are told that if we can perform the maintenance in the patching window that we can do our monthly maintenance tasks as well.

The Solution

Our solution is to create and deploy a task sequence which does our maintenance jobs and our patching all at once. So to begin we will create a blank task sequence.

Once we have done this, populate your task sequence with the tasks you require. In this example we are going to do the following things;

  • Run Defrag
  • Empty the temp directory
  • Clean out the prefetch directory
  • Apply Windows Updates
  • Restart the machine

Enter all these tasks into the task sequence and you will end up with something which looks like below.

So let’s take a deeper look at the task sequence and find out what we are running. Our first tasks is a simple Install Software Updates task sequence step, this is configured for All Software Updates as we just install everything anyway.

With the exception of Restart Computer, every other step is literally just a Run Command Line task sequence step. Let’s have a look in more detail.

Perform Disk Defragmentation

So this step is just running Defrag.exe with some switches, the full command we are running here is: Defrag.exe %SystemDrive% -v -w, we are also saying this command will run in%SystemRoot%\System32 just to make sure we pick up the command.

Here we are using environment variables so it can be run anywhere, regardless of disk configuration, we don’t want to hard code drive letters in here because we might have the situation where the OS is not on C: it’s actually on D:.

Cleanup Prefetch

Again, another basic command line which runs: Del.exe /F /S /Q *.*

We are also again setting the Start in value to %SystemRoot%\Prefetch, why is this? Well to prevent us having to cd to the directory we want to perform the command on, with del.exe you don’t provide a directory, you just run it when you have gone to the directory you wish to work on.

The same action runs for the Cleanup Temporary Directory task sequence step which runs the same command as above except the start in value is set to %Temp%.

Finally we have restart computer which indicates the maintenance is completed and restarts into Windows.

Deploying the Task Sequence

To run this monthly, remember on the last Friday of the month we do the following, select Deploy, make the sequence mandatory and then create a schedule as shown below.

Click OK to create the schedule, change Rerun behaviour to Always rerun program, skip over to Summary and then create the deployment. Then you should be done, this will run on the last Friday of every month and the performance of your clients should improve.

To Conclude

When working with task sequences, don’t just think operating system deployment, the task sequence can be used to perform all sorts of actions and maintenance is just one of them. You can easily expand this into creating some logging, writing some custom executables and scripts to perform some maintenance tasks or just letting users run them whenever, this could be on advise of your Service Desk or your Desktop Support team for instance.

Advertisements

Tags: , , , ,

About Martyn

Martyn is one of the Senior Cloud Architects and DevOps Team Leader at one of the worlds leading Cloud Transformation Specialists Inframon. Martyn is responsible for the architecture of some of the largest Azure deployments in EMEA and is a advisor to a many businesses on their strategies. Martyn is a regular speaker at Microsoft events and community events on Azure and DevOps, giving his insight to a growing number of audiences.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: