I’m really into Powershell so I like trying out all the available tools. Somehow I’ve missed the release of the PowershellShellPack which has ten modules offering all kinds of additional functionality including file handling, operating system information, GUI and code generation. I followed the Channel 9 video and ran into a problem on the first example given.

First I ran the command Import-Module PowerShellPack.

Powershell Import Module PowerShellPack

Then I tried to create, and display, a label as in the video example; New-Label “Hello World” -FontSize 40 -Show

Powershell STA modeerror

This resulted in the following error.

New-Object : Exception calling ".ctor" with "0" argument(s): "The calling thread must be STA, because many UI components require this." At C:\Users\Rhys\Documents\WindowsPowerShell\Modules\WPK\GeneratedControls\PresentationFramework.ps1:30292 char:29 + $Object = New-Object \<\<\<\< System.Windows.Controls.Label + CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

OK, I seem to need to be running in STA mode. I Googled “Powershell STA mode” and discovered a Stackoverflow thread. After reading this I thought I’d try starting Powershell with the switch -STA.

powershell start in sta mode

OK, that seemed to work. Now lets try to create that label again. First load the PowerShellPack modules again since we’ve started a new session.

Import-Module PowerShellPack

Now try to create the label again.

New-Label “Hello World” -FontSize 40 -Show

Powershell Hello World Label

OK, that’s that hurdle over. Now I can get on with exploring what this tool can do for me.