Today I’m going to demonstrate an ‘advanced’ concept in BatchPatch. We will use a combination of features, including the Job Queue, the Deployment feature, and bit of custom scripting to achieve the desired effect. The goal here is to illustrate how you can use BatchPatch to accomplish something that might not be directly built-in to the software.
Instruct BatchPatch to download and install Windows Updates on selected target computers ONLY if the target computers first past a check to see if they have enough disk space on their C drives. ‘Enough’ disk space is any number of megabytes that you choose.
Use the BatchPatch Job Queue to execute the following steps:
- Deploy a script to target computers that returns 0 if the amount of available C drive space is above the threshold that we set. If the amount of free space is below our threshold, then return 1.
- Use the Job Queue feature ‘Stop queue execution if previous action fails/errors’
- Execute ‘Download and install updates + reboot if required’ (or any desired action)
How to do it:
- I’ve created a very simple vb script that checks for free space on the C: drive and returns 0 if the number of megabytes free is greater than or equal to 500. If there are fewer than 500 megabytes free on C, then the script returns 1. Of course you can modify the threshold to be any number that you want. The contents of my script are below:
'Gets the free space on C drive. If free space is less than specified threshold return 1. Else return 0. 'Cocobolo Software LLC April 2017. on error resume next Err.Clear Dim freeMB Const MBCONVERSION = 1048576 Set objWMIService = GetObject("winmgmts:\\localhost\root\cimv2") 'Get C drive space Set colLogicalDisk = objWMIService.ExecQuery("Select * from Win32_LogicalDisk") For Each objLogicalDisk in colLogicalDisk If objLogicalDisk.DeviceId = "C:" Then freeMB = objLogicalDisk.freespace/MBCONVERSION End If Next If freeMB < 500 Then wscript.quit(1) Else wscript.quit(0) End If
- Save the script. The contents of the script above need to be saved in a text file with a .vbs file extension. For the sake of this example my script is called “DiskCheck.vbs”
- Create a deployment. The deployment will be used to copy the vbscript to the target computers, execute it, and retrieve the exit code. To create your deployment select ‘Actions > Deploy > Create / modify.’
- Browse to the location of your DiskCheck.vbs file, and then give the deployment a title. Click the ‘>>’ button to save the deployment. The screenshot below shows the configured deployment.
- With your deployment created and saved you can now setup your Job Queue. Go to ‘Actions > Job Queue > Create / modify.
- Select the desired steps of the queue. The first step executes the deployment that we created earlier. The second step tells BatchPatch to halt the queue if the previous action fails/errors (a script is considered failed/errored if it returns any non-zero value). The third and final step of the script is to execute whatever action is desired such as ‘Download and install updates.’ The screenshot below shows what your queue should look like:
- All we have to do now is execute the queue. Click ‘Execute now’ (or alternatively save the queue first and then execute it directly from the BatchPatch Job Queue menu). In the screenshot below you can see that I had less than 500 MB free on the target computer, and so the job queue halted, as desired. If there were 500+ MB available, then the job queue would have executed the final step to download and install updates.