Foreach now captures variables! (Access to modified closure)

Foreach has changed in C# 5.0! Consider the following piece of code in C# < 5.0: public class Test { public static void Main() { var words = new[] { “foo”, “bar”, “baz”, “beer” }; var actions = new List<Action>(); foreach (string word in words) { actions.Add(() => Console.WriteLine(word)); } actions.ForEach(e => e()); } } […]

When using an enum in PowerShell, use the member’s name, not the member’s value

Consider the following enum in C#: enum State { Started, Stopped, Unknown } Note that I have not added an explicit value for the enum members. They will be generated by the compiler. As stated in the C# spec: … its associated value is set implicitly, as follows: If the enum member is the first […]

ServerConnection and Login failed for user. Reason: Attempting to use an NT account name with SQL Server Authentication

Today I had to work with the ServerConnection class. This class provides a method to specify the connection to the Server class. So usage would be like this: # http://sqlblog.com/blogs/allen_white/archive/2008/04/28/create-database-from-powershell.aspx [System.Reflection.Assembly]::LoadWithPartialName(‘Microsoft.SqlServer.SMO’) [System.Reflection.Assembly]::LoadWithPartialName(‘Microsoft.SqlServer.ConnectionInfo’) $sqlServer = “server” $username = “username” $password= “password” $serverConnection = new-object Microsoft.SqlServer.Management.Common.ServerConnection($sqlServer, $username, $password) $server = new-object Microsoft.SqlServer.Management.Smo.Server($serverConnection) Write-Host (“SQL Version: {0}” -f […]

TeamCity reporting that it’s out of diskspace

I installed TeamCity on a server (just the professional edition). The server was installed under D:\TeamCity, with it’s (only) agent under D:\TeamCity\buildAgent. I then started creating a project. At one point I modified the VSC Checkout rules, and then stuff went downhill. First of all, a VSC root is not under some sort of revision […]

WebClient not sending credentials? Here’s why!

TL;DR version here. This post applies to more than just GitHub, read the rest to see the behavior! I was playing with the GitHub API (more specifically generating a new OAuth token). So what you need to do, as per the documentation, is to post a certain JSON string to https://api.github.com/authorizations, with Basic Authentication. I’m […]

Powershell, Where-Object and capturing the output

Again, one that thing I couldn’t find because there is just no documentation on Powershell. Try this: $foo = SomethingThatResturnsAList $foo = $foo | Where-Object { $_.Name -like “*something*” } PassOnFooToSomethingElse -List $foo Awesome, every sane developer would think: right, that would work. Except in Powershell. It appears that $foo on line 5 is $null […]

Powershell Remove-Item and symbolic links

Let’s say you’ve got a symbolic link which points to another folder and you want to delete the symbolic link through Powershell. Prepare for some weird stuff! Consider the following test script: New-Item “SymbolicTest” -Type Directory Set-Location “SymbolicTest” New-Item “Source” -Type Directory Set-Location “Source” New-Item “Test1.txt”  -Type File New-Item “Test2.txt”  -Type File New-Item “Test3.txt”  -Type File Set-Location “../” […]