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 […]

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 “../” […]