My Software Notes

Useful things I discover

Archive for August 2012

Adding PowerShell Automation to a .NET Application

with 3 comments

So I want to add PowerShell automation to my .NET app and according to MSDN (How to Write a Simple Host Application) I have to use the “Browse” feature of the “Add Reference” dialog in Visual Studio.  The location for the System.Management.Automation.dll is given as “Windows\assembly\GAC_MSIL\System.Management.Automation”.  But that may not always be correct.  See my note at the end.

Another, and I think better, way to do it is to open your project file and in the first “<ItemGroup>” section, add:

    <Reference Include="System.Management.Automation" />

This worked great for me.

Something to watch out for if you use the “Browse” method and you are using the Powershell 3 CTP: The dll is in a different location:


When I used the “Reference” method, Visual Studio referenced it without me having to do anything more.  Now that’s what I call service.


Written by gsdwriter

August 28, 2012 at 3:46 pm

Posted in .NET, Powershell, Visual Studio

Tagged with ,

List RSA Key Container Names

with 6 comments

Recently I’ve been looking into encrypting sections of web.config on a couple of web sites that reside on a web farm.

It’s not very difficult (once you figure out how to get around the fact that some of the instructions don’t work) and I’ll write another post on it once I’ve finished implementing it. But there is one major weak point: What happens if you forget the name of the key you are using?  Where do you go to find the names of the RSA keys?

You’d think that listing the names of RSA key containers would be simple.  After all, they are real easy to create just type:

aspnet_regiis -pc "MyKeys" -exp

(aspnet_regiis can be found in C:\WINDOWS\Microsoft.Net\Framework\v2.0.50727  or higher)

It’s so simple to do and yet if you forget the name you used then finding it again is virtually impossible.

After many, many searches on Google, Bing and DuckDuckGo, I finally found something that will list them.  (Surprisingly it was highest on the DuckDuckGo search and that’s how I found it.)

It’s a simple open source app called KeyPal.  Download it, open up a command prompt and run it.  At start up it gives you a list of user keys, a list of commands and a blank prompt (with no “>” or anything to indicate it’s a prompt).  To list machine level key containers just type “LM”, press Enter and there they are!

There is probably something in the bowels of Windows that will also do this, but I couldn’t find it after searching and searching, so kudos to the guys at JavaScience who wrote KeyPal.

I hope this gets onto search engines to help other poor slobs like me find out how to list RSA Key Container names without spending hours hunting.

Written by gsdwriter

August 6, 2012 at 12:08 pm