So yesterday, I had a coworker that was having issues installing updates on a Windows 7 VM that hadn’t been powered on in about a year. When he powered it up and tried to run updates, it wouldn’t do anything. I remember a few weeks back listening to Security Now! and remembered an episode where Steve had the same problem and discovered that he needed to install an update to the Windows Update Client. Unfortunately I couldn’t for the life of me remember what episode it was in. So I was going to open each of the show notes and search through the text to try and find this information. While I was opening the show notes, I noticed that they are all named the same, so I decided that it would be easier if I downloaded them all and then use a tool like AgentRansack to search the contents of the file. I thought a simple little download script wold be usefull here. My first thought was “It would be nice if I run a little wget script to download all the files” but I don’t have wget on my Windows laptop at work. So I figured out that there is a Powershell command to do the same thing, the Invoke-WebRequest command. I was originally going to just write a pure Powershell script to generate all the downloads, but I decided that would take more effort than I needed for this application (I would have to write the script and then sign in because of our security policies at work). So I found this to be a good opprotunity to use LinqPad to write a little C# script to build a download script. This was elegant becuase I just wrote a couple of lines of C# code to generate a list of the Invoke-WebRequest commands that I needed to run in order to perform the downloads. Here is the C# that I wrote:

1
2
3
4
5
6
7
8
9
10
11
void Main()
{
    for (int i = 1; i <= 554; i++)
	{
		string number = "";
		
		number = Convert.ToString(i).PadLeft(3, '0');
						
		("Invoke-WebRequest https://www.grc.com/sn/sn-" + number + ".txt -Outfile sn-" + number + ".txt").Dump();
	}
}

The output from running this script looks like this:

sn-1

I was able to copy the output from the script and simply paste it into my powershell window and it started mass downloading all the show notes onto my computer, I was then able to do a keyword search using Agent Ransack for the link in from the show that I wanted, get the update and get back to work! By the way, the link I was looking for was bit.ly/wupup