powershell bashrc equivalent

One complaint I hear a lot from the linux users who have to do windows admin work for a random project the most common thing I hear a complaint about is a bashrc equivalent. I’ve been asked about it a few times and knew you could do this at the local user level and replied with that but never thought about changing it at a system level.


If you’re mostly doing linux work you probably aren’t familiar with the scripting guy blog on microsoft.com. ¬†It has amazing content for doing windows automation work. Including a detailed description of how powershell profiles work ūüôā

Understanding the Six PowerShell Profiles

Churn (code)

One of the most useful things when you’re new to a codebase can be to look at version control and find out who owns what parts of the codebase and how where are the hottest spots in the codebase.

Corey Haines posted a gist years ago of a great way to get the second part of that info with various constraints.

churn number and file name
git log --all -M -C --name-only | sort | uniq -c | sort | awk 'BEGIN {print "count,file"} {print $1 "," $2}'

churn number and file name w/ limiting to last n commits
git log --all -n 5000 -M -C --name-only | sort | uniq -c | sort | awk 'BEGIN {print "count,file"} {print $1 "," $2}'

graph of churn number and frequency
git log --all -M -C --name-only | sort | uniq -c | sort | awk '{print $1}' | uniq -c | sort | awk 'BEGIN { print "frequency,churn_count"} { print $1,$2}'

It is fairly trivial to take these and turn them into a git extension that lets you simply do “git churn”. Many people have these in their dotfiles repos on github.

ASP.Net pages don’t display. Console just says connection refused.

Every now and then you run into errors that don’t seem to have a cause and just show you blankness.

In ASP.Net MVC I’ve ran across trying to debug a site and chrome only says “This webpage is not available“.

Looking at the console you’ll see a line that says:

Failed to load resource: net::ERR_CONNECTION_REFUSED

If this was python or ruby I’d likely be looking at built in logs and possibly D-Trace or S-Trace to see what is going on. Since it is on windows the tool I check right away is the event viewer. I checked Application events and there was nothing of importance but checking System Events reveals an error.


Unable to bind to the underlying transport for [::]:58926. The IP Listen-Only list may contain a reference to an interface which may not exist on this machine. The data field contains the error number.

So with the information that we can’t bind to port 58926 the next information that makes sense to track down is what is on that port. That means it is time to break out netstat:

netstat -ano | grep 58926

*If you don’t have grep installed (I get this via msysgit) you can also use powershell: netstat -ano | select-string -simple 58926
With the process id (on the far right of the output) take a look at what needs to be killed using task scheduler. In this case apparently chrome has the port bound so kill chrome and then everything should be good. (Wasn’t that the theme of the first BUILD conference?)


What SSIS jobs are executing and how do I stop one?

Every now and then an SSIS job is still running and you want to kill it to start it over with a fix you made(…in test right, you’d never let this happen in production).

There is a view in the SSISDB that will tell you what is running, and a stored procedure that can stop the running SSIS packages.
select * from catalog.executions where end_time is null

Exec catalog.stop_operation @operation_id = 33

Simple service status checks and changes with powershell

We have a lot of third party applications with which we integrate. This tends to mean that there are a lot of windows services we want to make sure are running.  Typically this is left to operations departments, but sometimes (or to my experience, most times) you want to track this on your own.  Trust but verify.


Powershell is great for this. Simply use the Get-Service command with its -ComputerName param.

PS C:\users\scl>Get-Service -Name QuartzServer -ComputerName OMGITSASERVER

Status   Name               DisplayName
------   ----               -----------
Stopped  QuartzServer       Quartz Server

To change the status of the service you query for you can pipe the result to Set-Service.

PS C:\Users\scl2> gsv -Name QuartzServer -ComputerName OMGITSASERVER | set-service -status running

PS C:\Users\scl2> gsv -Name QuartzServer -ComputerName OMGITSASERVER

Status   Name               DisplayName
------   ----               -----------
Running  QuartzServer       Quartz Server

gsv is a default alias of Get-Service.

SQL Server File Expansion Performance

Moving some old notes over to blog posts and I ran across the problem of SQL Server needing to increase file sizes.

Make sure the user running SQL Server also has permission to: Perform Volume Maintenance Tasks

The reason for this is the following:

Data and log files are initialized to overwrite any existing data left on the disk from previously deleted files. Data and log files are first initialized by filling the files with zeros when you perform one of the following operations:

  • Create a database.
  • Add files, log or data, to an existing database.
  • Increase the size of an existing file (including autogrow operations).
  • Restore a database or filegroup.

In SQL Server, data files can be initialized instantaneously. This allows for fast execution of the previously mentioned file operations. Instant file initialization reclaims used disk space without filling that space with zeros. Instead, disk content is overwritten as new data is written to the files. Log files cannot be initialized instantaneously.

In order to make use of Instant File Initialization the SQL Server user must be a member of the Perform Volume Maintenance Tasks group.


Awesome Error Messages – 1

IIS Express – The specified port is in use


Somewhere between using webdeploy to send files to a dev server a few times yesterday I started getting this message locally.  Googling for it turns up lots of results of how to change your port etc.


The root cause of this message in my case was that Entity Framework was looking for a connection string that didn’t exist in my config files. ¬†I’d renamed it to match another that we use for the same database in a different application that is deployed in the machine.config file on our servers. Creating a DB Context in the constructor for the default controller caused IIS Express to toss this message and fail to load pages.