Archive for Scripts

Script to see if a KB update has been installed on a computer

Often, when I am working on a workstation or server, I need to see if a particular KB update has already been applied (installed). Case in point: KB 2862330 was released in October as part of a set of USB/Kernel updates. Immediately there were reports of BSODs with Windows 7 and Windows 2008R2 systems.

Early investigation of this issue found that the BSOD could be avoided in most cases if KB 2533552 was installed prior to installing 2862330.

So, I found myself looking for a simple, easy way to determine if a KB update has been installed on a particular workstation. Gandlaf50 from the Spiceworks’ community forum posted a VB script solution. The script will ask you which computer to check, meaning you could run this from your workstation, and check another computer in your network.

  1. Download the script file to your computer
    image
  2. Rename it from findkb.v_b_s to findkb.vbs
  3. Double click to run the script.
  4. Enter the KB number you wish to check (enter just the number)
    image
  5. Enter the name of the computer to be checked
    image
  6. A message box will display informing you if the KB is installed or not.
    image

Voila!

Cleanup Log Files (Batch vs PowerShell)

Back in Nov 2006 I wrote a blog post on creating a batch command file that could be used to cleanup old IIS log files. Then, in Dec 2007, I wrote an updated blog post with another solution. I thought I would update those posts for 2013 using PowerShell.

OLD SCHOOL (Batch command file)

Both of the above solutions were written in the SBS 2003 era, but will work with SBS 2008/2011. Both versions will let you identify the number of days to keep (I suggest 30 days), and will scan sub-folders under the specified folder.

As a quick review, here’s how to implement my Dec 2007 solution:

  1. Download the zip file from my web site which contains three files: .vbs, .bat, and .log files.
    image
  2. Extract and copy those three files to your desired directory. I normally use c:\scripts.
  3. Edit the .bat file to point to the appropriate parent folder of the log files to be cleaned up, and the number of days of log files to retain.
    For Windows 2008 R2, my .bat file looks like this:
    image
  4. NOTE: If running this for the first time, you may wish to test drive the script, without actually deleting any files. To do this, edit the deloldfiles.vbs file and comment out the ‘file.delete’ line in the script by adding a single quote (‘) to the start of the line. If all works, go back and remove the single quote.
  5. After testing the script manually, all that is left is  to schedule the script to run on a weekly or monthly basis, as desired.

NEW SCHOOL (PowerShell)

While batch files are still supported in the Windows 2008 R2/Windows 2012 era, we need to start getting comfortable with using PowerShell scripts. I found a handy PowerShell script that does this from the Microsoft forum.

This script used the “start-transcript / stop-transcript” command to create a history log of files deleted.

  1. Download the PowerShell script file (deloldfiles.ps1) from my web site.
  2. Edit the script, as necessary, to point to the appropriate parent folder and the number of days to retain, and save.
  3. NOTE: the script includes a “–whatif” option that allows us to run the script without actually deleting anything. If the script appears to work as expected, then simply remove the –whatif option from the script. Be sure to leave the trailing brace } in the script.
    image
  4. To run, right click on the .ps1 file and click ‘Run with PowerShell’
  5. After testing the script manually, don’t forget to schedule it to run on a weekly or mothly basis.

Finally, from the FWIW department: you should know that from a security point of view,
deleting IIS log files or other similar system log files, is not generally recommended.