Sunday, September 14, 2014

This is my next: Site Reliability Engineer at Stack Exchange

AvoidInjuryIn my career I have been very lucky to work with some great people at incredible companies, and although there have been a few curveballs along the way I have always felt like I was exactly where I was supposed to be. Well a few months ago I stumbled across an open position at a company I admire that fit my skill set, and while I was enjoying my current position at 3M HIS I knew I would regret if I didn’t at least investigate the opportunity. Fast forward to today and I am excited to announce that next week I will be starting a new job as a Site Reliability Engineer (SRE) at Stack Exchange focusing on Windows and PowerShell.

The company is based out of New York, but I will be working remotely from home to make sure that the world’s best network of Q&A sites is always available to answer any questions you may have ranging from Bicycles to Mathematics, Scifi to Skeptics, and Cooking to Home Improvement. I have used their original trilogy of websites on just about a daily basis to get answers to questions about programming, system administration, and general PC issues. I have watched as the company grew from a idea about how to improve the Q&A experience into one of the top 100 network of websites in the US and experienced a few curveballs of their own along the way.
In my new position I will get to work with an all-star team of system administrators and software developers and be a part of a community that has quickly become an integral part of the software development experience (and other online communities). I am excited to be in a position where sharing knowledge and experience is a core tenant of the company and where I am encouraged to both use and contribute to open source projects. I can’t wait to dig into the Tools and Hardware, and who knows, I may even have something interesting to talk about at a future users group or conference.

Create TFS Patch File With Pending Changes using TF and 7Zip

I recently had to do a TFS migration and upgrade and during that process needed a way to copy pending changes between the Production and Staging TFS servers. The goal was to be able to test the upgrade in a stage environment, modify the build scripts so that they worked using a new code structure, and then create a patch file that could be applied to the production instance of TFS. I checked online and found a solution that used the unified diff feature of the tf.exe program, but this didn’t work very well if you had to checkout or add many files as part of applying the patch. Also instead of creating a large TXT file I wanted a ZIP file that had full versions of all the files that were modified in the current workspaces.

After playing around with the tfvc commands I was able to write up a PowerShell script that would detect any pending changes in your current workspace and then use 7Zip to create a patch file with just those files. Here is an example of the Export-TFSPatch.ps1 script:

image

Here you can see it detected 10 files that were checked out in the workspace and created a zip file with just those files:

image

You can then copy that zip file to another system and use the Apply-TFSPatch.ps1 script to apply those changes to the new workspace. This includes checking out any existing files so they can be overwritten and adding any new files from the patch to the TFS workspace.

image

After applying the patch you can then use TFS to check in the pending changes on your workspace:

image

If you want to use these scripts you can find them at my CodeBlog Github repository.

The TF.exe command is very sensitive to which version of Visual Studio you used to create your workspace, so if it complains try changing the $tfexe variable to use 11.0 (VS2012) or 12.0 (VS2013).

Wednesday, June 25, 2014

Notepad++ Save As Admin Plugin

I’ve used Notepad++ for a while now, but only recently started exploring all the various plugins that are available. One very helpful plugin is called “Save as Admin”, which can overcome a common issue when trying to edit files for which the local Users group does not have modify permissions. This often happens with web.config files, which by default live in a folder that only Administrators can modify. Even if you are a member of the Administrators group, you will still receive a “Save Failed” error message asking “Please check if this file is open in another program.” when you try and save any changes:

Please check if this file is opened in another program

If you check the permissions of the file, you will see the Users group only has read & execute, and does not have modify permission:

image

To fix this you have a few options:

  1. Close Notepad++ and re-open it as an administrator.
  2. Use the edit button on the security tab of the file properties to give the Users group or your individual user modify permissions.
  3. Save the file to another location like your desktop, and then copy from there into the destination folder. This will cause Explorer to display a “You must be an administrator to perform this action” window, but it will allow you to use your Administrator role to complete the action.
  4. Use the “Save as Admin” plugin in Notepad++ to elevate to the Administrator role and save the file.

If you have already made changes to the file and do not have the plugin installed, option 2 or 3 is the only way to keep those changes (the others require closing and reopening Notepad++). Once you install the “Save as Admin” plugin you can then use that to overcome any permissions issues.

To install the plugin open the Plugin Manager:

image

Type the letter S to find “Save as Admin” and check the box. You can install multiple plugins at once, and I recommend also adding “Compare”, “Reload"Button”, and “XML Tools”.

Save as admin plugin

Once you have selected the plugins you want press the Install button. It will download and install the plugins, most of which show up under the Plugins folder. When finished it will prompt you to restart Notepad++

image

NOTE: if you had pending changes to a file you may see the following:

image

There are actually two dialogs here, and the second one is hidden. You will need to click the grey bar behind the blue bar (or just click on Notepad++ in your task bar) to display the hidden window:

image

Here you should press no (loosing any changes) or yes and save to another location. Notepad++ should then restart. Now when you try to save a file that requires Administrator privileges you will get a UAC prompt:

image

Pressing Yes will allow Notepad++ to save the file using your administrator role.

Monday, January 6, 2014

Tx.Windows Parsing WC3 IIS Log files in LINQPad and PowerShell

I saw a tweet today from the @ReactiveX account about a new release called Tx (LINQ to Logs and Traces). It appears to have a lot of plumbing to use the Reactive Extensions (Rx) to parse through Event Logs and Event Tracing files. One of the slides on the Tx Codeplex site also mentioned parsing IIS W3C Logs, which is something I spend a fair amount of time doing.

Even better Tx has a custom LINQPad Driver, which is one of my favorite tools for playing around with LINQ and Rx. I downloaded the sample traces and was able to view low level event tracing details from the HTTP.sys driver used by IIS, but I didn’t immediately see how to parse the IIS log files using Tx. After downloading the source I found a W3CTest.cs file that showed how to parse log files using the Tx.Windows.W3CEnumerable.FromFile or FromFiles methods.

To use this in LINQPad you do NOT need the Tx Driver, but instead you use F4 to add a reference to the Tx.Windows Nuget package:

image

image

Once the reference is added to your LINQPad query, you may also want to add the following additional namespace imports:

image

This gives you access to the common LINQ functions used in the Tx samples. Now I can write a query in LINQPad that uses the W3CEnumerable to parse the log files. You can write complex LINQ queries or use the toDataGrid parameter of the Dump method to display the data in a grid format:

image

After I had it working in LINQPad, I next thought: “Why can’t I use this in Powershell?”. The Tx library targets .NET 4.0 and 4.5, so as long as you have PS 3.0 or later you can add a reference to the Tx.Windows.dll and then use the W3CEnumerable class to work with Log files.

#Load Tx.Windows.dll from current user’s LINQPad nuget local cache
[Reflection.Assembly]::LoadFile("C:\Users\$($env:username)\AppData\Local\LINQPad\NuGet\Tx.Windows\Tx.Windows.1.0.31229\lib\Net40\Tx.Windows.dll")

#Load log file and sent output to screen
$log = [Tx.Windows.W3CEnumerable]::FromFile("C:\inetpub\logs\LogFiles\W3SVC1\u_ex131230.log")
$log | select -Last 10 |  ft dateTime,cs_method,cs_uri_stem,cs_uri_query,cs_username,sc_status,time_taken

#Sent log to gridview
$log | out-gridview

image

The Gridview is very helpful since you can add filters to target specific entries similar to a LINQ query

image

All this in the first hour of playing with Tx! I am really excited to see if we can use Tx with IIS Failed Request Tracing or ASP.NET Tracing to track down issues in our .NET web apps.

Blog.TheG2.Net - Your guide to life in the Internet age.