PowerShell 32/64bit Execution Policies

When it comes to bit-ness of an application, there's generally only 2 things you need to worry about:

Am I running the right version for the OS?
Are all the components compatible with the same version?

I don't think I've come across any instances of configuration settings being applied differently to different versions of the same application. But PowerShell is different.

When managing environment settings such as Execution Policies in PowerShell, the settings actually need to be changed for the right version, and the right version depends on the application calling the runtime. Shown below are the 2 different versions of the PowerShell shell which comes with Windows, after running Get-ExecutionPolicy at the same time:

PowerShellRuntime

Annoyingly, if these do not match up, and you run an application built for 32 bit rather than 64 bit without realising it, you will get a CmdletInvocationException:

 CmdletInvocationException

Hope this helps someone.

Custom Configuration Section Collections

I'm sure this should be easy, but it's taken me most of a morning of reading MSDN and tweaking code to get it to work. Most of the documentation that I have found has either been massively out of context, showing small segments of code and not explaining where it fits in or what it does; or it's been hugely over complicated, showing complete examples with masses of boilerplate code.

I've been trying to get a simple collection, using <AddElement> tags to add a list of items, similar to how AppSettings and ConnectionStrings sections work. It was extremely easy to create a custom configuration section, with a single item and associated properties - creating a collection of items, with add/remove/clear functionality appeared to be a different matter.

Turns out, it's actually not that difficult. 3 classes, 2 overrides, and some properties. After that, it's just a case of registering the custom section in the configuration file in the <configSections> section.

Section class

The section class inherits from ConfigurationSection, and serves as the wrapper for your configuration section in the app.config file. This is what you'll add to the <configSections> attribute to register the type in the Configuration manager:

public class ElementSection : ConfigurationSection
{
    [ConfigurationProperty("Elements", IsDefaultCollection = false)]
    [ConfigurationCollection(typeof(Elements), AddItemName = "AddElement", ClearItemsName = "ClearElements", RemoveItemName = "RemoveElement")]
    public Elements Elements
    { get { return this["Elements"] as Elements; } }
}

Collection class

The collection class is required to tell the Configuration manager what to create and what to use to retrieve the elements. There are 2 required overrides for this class:

public class Elements : ConfigurationElementCollection
{
    protected override ConfigurationElement CreateNewElement()
    {
        return new Element();
    }

    protected override object GetElementKey(ConfigurationElement element)
    {
        return (element as Element).Name;
    }
}

Element class

The class that contains your actual elements, all that's required here is a property for each value you want to store against the element, which needs to be decorated with the ConfigurationProperty attribute.

public class Element : ConfigurationElement
{
    [ConfigurationProperty("Name", IsRequired = true)]
    public string Name
    { 
        get { return (string) this["Name"]; } 
        set { this["Name"] = value; }
    }
}

app.config registration

The app.config file registration should be fairly trivial, all that's required is the name you want to give the section, the namespace and class name, and the assembly name:

<configuration>
    <configSections>
        <section name="ElementSection"
                     type="namespace.ElementSection, AssemblyName />
    </configSections>
</configuration> 

And that's all there is to it. If anything is not clear, drop a comment and I'll try to clarify.

vSphere Client White Screen Fix

There is a known issue when running vSphere Client 4.1 and accessing the console of a VM running on an ESX/ESXi 3.x host:

VMWare KB: vSphere Client displays a white screen when accessing the virtual machine console 

"Symptoms

You may observe these after installing vSphere Client 4.1:
You see a blank white screen when opening the virtual machine console for a virtual machine running on an ESX/ESXi 3.x host
No errors are reported on the vSphere client Virtual machine consoles to ESX/ESXi 4.0 or 4.1 virtual machines open without any issues"

The resolutions to this are just a little bit tedious, and after putting it off for a couple of months, I thought I'd see if I could find another solution. And I did.

In the VMWare forums, there is a comment which mentions that running bcdedit to disable DEP (Data Execution Prevention) resolved the issue.

DEP is a security feature switched on by default in most modern OS's, and I'm not comfortable switching it off entirely, so I tried to just exclude the VpxClient.exe.

The 4.1 vSphere client was compiled with the NXCOMPAT flag enabled, which forces DEP to be enabled, and stops you from adding the application to the exclusions list. I've not been able to find the exact reason, but whatever it is, it's DEP that causes the white screen to display.

The NXCOMPAT flag can be removed from an application using the editbin utility, which comes with most versions of Visual Studio (including the Express editions).

editbin.exe /NXCOMPAT:NO [FileName]

Running the command above will allow you to add the application to the exclusions list.

If you do not have editbin available, I have wrapped the required files up in a zip file, and added a PowerShell PS1 script to perform all the required actions.

Download it here.

Just extract the files to a folder, open PowerShell as Administrator, and run the included .ps1 script.

Hope it helps!

Umbraco Installation

Having attempted to run a blog using BlogEngine .Net, I realised I needed (wanted) something a bit more polished.

I've looked around at a couple of CMS (CMSes?) to see if there's anything I like, and Umbraco seems to stand out from the crowd as being polished, full featured, and easy to use. I don't want (need) any "power tools" for blogging, but I do want to be able to add static pages easily, without worrying about it impacting the blog side of things.

Although this was possible with BE.Net, it seemed to be more hassle then it was worth, and I quickly gave up.

It's been nearly 2 years since I last wrote a blog post, and although BE.Net is a good system, I'm going to blame it for me not keeping up with blogging.

What's New in the BCL in .NET 4

An excellent overview of the new additions to the BCL in .Net 4 Beta 2:

http://blogs.msdn.com/bclteam/archive/2009/10/21/what-s-new-in-the-bcl-in-net-4-beta-2-justin-van-patten.aspx

Particularly happy with String.IsNullOrWhiteSpace, and looking forward to playing with the System.Device.Location namespace for Windows 7.

Check it out, the additions to beta 1 are also listed on an older post.

"There are still remote logins or linked logins for the server 'linkedservername'."

I was trying to clear up a linked server in MS SQL 2005, and kept getting:

"Msg 15190, Level 16, State 1, Procedure sp_dropserver, Line 56
There are still remote logins or linked logins for the server 'linkedservername'."

So I checked sys.linked_logins, and true to it's word, there were still a couple of linked logins associated with 'linkedservername'. I quickly looked through the system SPs, and found a sp_droplinkedsrvlogin, so I ran it with the 2 usernames that were in the sys.linked_logins table, got the satisfying "Command(s) completed successfully." message, re-ran the sp_dropserver SP again. Huh? Whaddya mean "There are still remote logins or linked logins for the server 'linkedservername'."???

I googled about a bit, and all I got was "run sp_droplinkedsrvlogin for all linked logins...". After a couple of minutes, I did some digging into what the system SPs were actually doing:

 EXEC sp_helptext sp_dropserver;

Gave me this snippet:

 if @droplogins is not null AND @droplogins <> 'droplogins' 
 begin 
  raiserror(15600,-1,-1, 'sys.sp_dropserver') 
  return (1) 
 end 

So it seems to remove a linked server that still has logins associated, you need to run "sp_dropserver 'linkedservername', 'droplogins'".

On further digging, I found that the sp_droplinkedsrvlogin SP allows the second parameter to be passed in as NULL, and that will also remove all existing logins from the specified linked server.

Enjoi!

Google to launch new OS

In Google's latest attempts at slaying Microsoft, they've announced their plans to release a new OS based on Chrome.

Google Chrome OS is an open source, lightweight operating system that 
will initially be targeted at netbooks. Later this year we will open-source its 
code, and netbooks running Google Chrome OS will be available for 
consumers in the second half of 2010. Because we're already talking to 
partners about the project, and we'll soon be working with the open source 
community, we wanted to share our vision now so everyone understands 
what we are trying to achieve.

Apparently built on top of the linux kernel, the security architecture is being completely redesigned to make it as secure as possible, as they did with the Chrome browser. And although the job they did on Chrome wasn't exactly perfect, it has been unbreakable to truly exploitable vulnerabilities in competitions.

They seem to be targeting the perfect market with netbooks, and I can certainly see the appeal this kind of OS will have for such a platform. But other than for kiosks, and possibly some older machines struggling under the weight of Windows, I don't see much appeal for day to day use.

I don't know what the figures are for the amount of netbooks versus laptops and desktops, but I'm pretty sure that although this will definitely make a dent in Microsoft's share of the portable market, it's certainly not going to be a giant killer, not with it's first incarnation at least.

A win for Privacy?

This seems like it was always inevitable to me:

Shares in the online ad firm Phorm have fallen by 
more than 40% after BT said it had no immediate 
plans to use the service that tracks online behaviour.

Phorm builds a profile of users by scanning for 
keywords on websites visited and then assigns 
relevant ads.

Considering it's main purpose, and it's method for doing so, I hope this is the beginning of the end for Phorm. However, if what they say about their success elsewhere is true, we may not be so lucky:

"In addition to making excellent progress in 
South Korea, we are engaged in more than 15 
markets worldwide including advanced negotiations 
with several major ISPs."

Fingers crossed though.

Enjoi!

UPDATE:
Add to this, TalkTalk has also pulled out, so it's looking even better for UK users.