Mr Andersson

Enable-PSRemoting is broken in PowerShell?

with 2 comments

Yesterday I installed the RTM bits of WinRM 2.0 on a Windows Server 2003 machine and it were really no issues at all getting it working.

Today I tried to do the same thing but on a Windows 2008 Server (R1) that is not joined to any domain, and it fail on step 1 of the configuration.
In both cases I started out downloading the patch. Then I run “Enable-PSRemoting” in an elevated PowerShell prompt, which succeeded on the Windows 2003 Server but not on the Windows 2008 Server.
The error I got was “Access denied”.
I thought I followed the troubleshooting guide for WinRM, but apparently there is slight difference of two different ways I found on how you set this up. You can either run “Enable-PSRemoting” or you can run “winrm qc”. If I run the quick config tool using the “winrm” command everything works out just fine, but if I use “Enable-PSRemoting” I get “Access denied”.
The most mysterious part of this is that “Enable-PSRemoting” WORKED on Windows Server 2003, but not on Windows Server 2008. Strange!
If you have any clues about this, please leave me a comment!
Advertisements

Written by anderssonjohan

November 18, 2009 at 07:57

Posted in scripting, troubleshooting

Tagged with ,

Note to self: If you get error code 12250 from ISA server 2006


leave a comment »

“Error Code: 403 Forbidden. ISA Server is configured to block HTTP requests that require authentication. (12250)”

Everything works from and to the protected networks but traffic from the external network is blocked with the error response above.
Solution: Stop using the darn “Publish web site” wizard and copy already existing stuff 🙂
-or- make sure that the “Allow client authentication over HTTP” check box is checked.
Found at the HTTP Listener properties – Authentication tab, click Advanced.

Written by anderssonjohan

November 17, 2009 at 07:30

Posted in troubleshooting

Tagged with ,

Swedish Alt.Net UG Coding Dojo at Avega, Stockholm

with 2 comments

Yesterday I was at my very first Coding Dojo with my fellow collegues Morten and Sebastian. I was somewhat nervous before this event. Coding in group is not an every day occasion for me :). But it went very well and I can only concur on what Morten blogged about.

Adding to that I must say it were so popular that we needed to split up into two conference rooms. Each room was equipped with a projector, a decent table with room enough for about 15 people.
However, even though we split up into two teams (that focused on the same Kata, see link in Morten’s post), we were just too many people around the table. I’m not sure about the exact head count but I guess we ended up with about 9 or 10 people. The most disappointing thing was that one guy was “rolling his own private solution” on his machine during the session. No hard feelings though; I believe this is a sign that we had too many participants in each group.
Worth to say is that each rotation was time limited to 4 minutes with a break of 15 seconds. That means each 4 minutes you rotate around the table and the next person takes the keyboard and continues where the last person left off. The person to the left of the person at the keyboard is the navigator in the pair.
Really nice experience and very nice and bright people in the user group! Thanks Avega (especially Joakim Sundén and his collegues) for hosting the meeting at their office here in Stockholm.
Today I couldn’t resist thinking of how we could do this internally at work (we’re 6 persons writing code at RemoteX so it seems to be just too perfect). Oh, so much cool code to write, so little time. 🙂

Written by anderssonjohan

November 11, 2009 at 23:01

Posted in events, programming

Tagged with , , ,

Pimping PsUnit with constraint based assertions

leave a comment »

Using PsUnit one can set up scripted “unit tests” for PowerShell scripts. I have sort of just started using PsUnit at work and right now I feel that a lot of the basic features of other test frameworks are missing.

PsUnit has one function for doing constraint based assertions. This may be familar to those who are using NUnit. Basically the syntax for this is:
<![CDATA[
$result = DoSomething
Assert-That $result { $ActualValue -eq “expected value” }
]]>

Using NUnit and this constraint based model, a simple assertion can look like this:
<![CDATA[
Assert.That( myString, Is.EqualTo(“Hello”) );
]]>

I quite don’t like the “barebone” scriptblock you need to write to use Assert-That in PsUnit, so here is what I came up with (using my example of above):
<![CDATA[
$result = DoSomething
Assert-That $result (IsEqualTo “expected value”)
]]>

I also added another constraint which allows you to assert that some code throws something:
<![CDATA[
# The following assertion will always pass
Assert-That { throw “blah!” } (ThrowsException)
]]>
This complements the already built-in feature of PsUnit which allows you to add a parameter, $ExpectedException, to the test. If you have been using MSTest you would use the method attribute ExpectedException for this.

Here is another example which tweaks the constraint to a somewhat more specific type of exception:
<![CDATA[
# The following assertion will fail since throw in PowerShell creates a System.Management.Automation.ErrorRecord
Assert-That { throw “blah!” } (ThrowsException -Exception $([System.ArgumentException]))
]]>

A more usable test using the ThrowsException constraint could be:
<![CDATA[
Assert-That {
# The following web resource does not exist, thus an error should be the result
Get-Http “http://blogger.com/asdfg&#8221;
} (ThrowsException -Exception $([System.Net.WebException]))
]]>

The biggest improvement using these new constraints is the output in the test result.
While using PsUnit out-of-the-box…
<![CDATA[
$foo = “bar”
Assert-That $foo { $ActualValue -eq “foo” }
]]>
…results with “Assert-That returned false!” in the test result.
Using the constraint in this blog post…:
<![CDATA[
$foo = “bar”
Assert-That $foo (IsEqualTo “foo”)
]]>
…results with “ActualValue ‘bar’ is not equal to expected value ‘foo’“.

The same level of detail is provided by the ThrowsException constraint, which may result in “No exception was thrown, expected exception of type ‘System.ArgumentException’“.

Any ideas, suggestions etc.? Please don’t hesitate to drop a comment!

Written by anderssonjohan

November 11, 2009 at 20:41

Posted in scripting

Tagged with ,

Integrating PsUnit and MSBuild

leave a comment »

The last month I have been digging into, adding new and refactoring the Powershell scripts we use in RemoteX Applications. We primarily use PowerShell to configure and deploy our product.

More often or too many times – with our latest releases – our fellow collegues at Customer Operations have been telling us “The xyz powershell script doesn’t work anymore, what have you done to it???”
I could have answered: “- We don’t have automated tests on those scripts, so what do you expect? Manual testing? Pfffff…”, but for obvious reasons I didn’t :).
So it was time to add some automated tests for those scripts so I could get this guy at Customer Operations back to work.
All compiled code (C#) is automatically tested in our Continuous Integration builds when someone checks in, but until now we haven’t had automated tests for our PowerShell scripts. With “automated” I mean that a test runner executes a test suite during a build.
In order to test our PowerShell scripts I have started using PsUnit. Since we are using Team Foundation Server and MSBuild for our CI builds, I needed to integrate PsUnit with MSBuild somehow.
There are several ways to invoke Powershell from an MSBuild script – we have chosen the Exec task which invokes powershell.exe.
First of all I created a separate build target which invokes PsUnit:

<![CDATA[
<PropertyGroup>
<CoreTestDependsOn>$(CoreTestDependsOn);RunPsUnit</CoreTestDependsOn>
<RunPsUnitDependsOn>CoreRunPsUnit</RunPsUnitDependsOn>
</PropertyGroup>

<Target Name=”RunPsUnit” DependsOnTargets=”$(RunPsUnitDependsOn)”/>
<Target Name=”CoreRunPsUnit” Condition=” ‘$(RunTest)’!=’false’ “>
<Exec Command=”$(PowerShell) -Command &quot;&amp;{ .\runpsunit.ps1 -PsUnitTestFile %(PsUnitTest.FullPath) }&quot;”/>
</Target>
]]>
Using this batch target, all that needs to be done is to add PsUnitTest items to the build script. Just like the way we set up TestContainer items for use with MSTest:
<![CDATA[
<ItemGroup>
<PsUnitTest Include=”$(SolutionRoot)\Scripts\Tests\*.Test.ps1″/>
<PsUnitTest Include=”$(SolutionRoot)\References\PsUnit\*.Test.ps1″/>
</ItemGroup>
]]>
So far so good, but when tests are failing, the build is successful. This is because the Exec task only reports a build error when the executed command returns an exit code other than zero (0x0). So I started looking into the test runner of PsUnit (PsUnit.Run.ps1) and discovered that it didn’t send any output nor produced some other exit code than 0x0. The only output PsUnit will send you is some nice colorful information written to the PowerShell host.

So I ended up with the following:
1. this tiny tweak at the end of PsUnit.Run.ps1:

<![CDATA[
$TestResults
]]>
This makes PsUnit.Run.ps1 send the test results along the pipeline.

2. A small wrapper for the test runner which returns some exit code other than 0x0 to the Exec task in MSBuild:

<![CDATA[
$results = Invoke-Expression “$psUnitRun -PsUnitTestFile $PsUnitTestFile”
$results | % {
if( $_.Result -eq “FAIL” ) {
throw “Test run failed: $($_.Test) – $($_.Reason)”
}
}
]]>
This makes the Exec task report a build error if we find any failing test in the test result from PsUnit – and last but not least – the name of the failing test and the reason ends up nicely in the MSBuild log file.

So now when somebody checks in a change to compiled code, which affects the result of our setup scripts, we will be able to detect errors ASAP! Yay!

Written by anderssonjohan

November 11, 2009 at 19:50

Posted in scripting

Tagged with , ,

Yay, PowerShell v2 is finally RTMed!

leave a comment »

PowerShell v2 is finally RTMed for the rest of us who still has a couple of boxes not running Windows 2008 Server R2 or Windows 7.

Downloads and info for Windows Server 2003, Windows Server 2008 (R1), Windows Vista and Windows XP.

Written by anderssonjohan

November 9, 2009 at 16:01

Posted in scripting

Tagged with

Timjankyckling med rotsakspytt

leave a comment »


Mor och far brukar göra en grymt god rotsakspytt som passar bra pÄ hösten. Jag kör en repris av kyckling och parmigiano-reggiano som en avslutning pÄ höstlovet/vecka som grÀsÀnkling.

PS. Det Àr inte utan viss lÀngtan efter den bestÀllda HTC HD2 luren man publicerar detta. Bilderna tagna med min HTC Tytn II Àr verkligen hur suddiga som helst. DS.

Ingredienser
  • KycklingfilĂ©er
  • Potatis
  • KĂ„lrot
  • VitkĂ„l
  • Morötter
  • Lök (gĂ€rna purjolök och charlottenlök)
  • Ost (gĂ€rna med lite smak)
  • Timjan
  • Paprika(krydda)
  • Peppar
  • Smör, olja
LĂ€gg kycklingfilĂ©erna i en ugnssĂ€ker oljad form. Krydda med paprika, timjan och peppar. SĂ€tt in i förvĂ€rmd ugn pĂ„ 175 grader i c:a 60 minuter. TĂ€rna upp potatisen i lagom smĂ„ delar. VĂ€rm en stekpanna med smör i. LĂ€gg i potatisen. Hacka löken och tillsĂ€tt i pannan nĂ€r potatisen har hunnit gotta till sig lite i smöret. TĂ€rna upp/hacka kĂ„lroten, morötterna och vitkĂ„len och lĂ€gg i pannan. LĂ„t stĂ„ och puttra med lock ett tag. TillsĂ€tt mer smör vid behov. Riv osten och tillsĂ€tt nĂ€r kycklingen har c:a 15 min kvar. Ät och njut!

Written by anderssonjohan

October 31, 2009 at 18:52

Posted in food

Tagged with