My Software Notes

Useful things I discover

Archive for the ‘Powershell’ Category

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 ,

Launch a Powershell console with Administrator rights from a Powershell console without Administrator rights

leave a comment »

That title is a mouthfull, but the good news is that the Powershell command to do it takes less characters.

It’s really simple once you have hunted around on the net for a while:

Start-Process "$psHome\powershell.exe" -Verb Runas

That’s it.

Open a regular PS console and type that.

I’ve only tried it on my own machine where I am an admin and I have UAC turned on. When I try it I get the UAC prompt, followed by a nice PS admin console.

I got it from this: Re-launch Powershell Script Elevated


This is bad, but I couldn’t resist it.  I’m a big fan of “Young Frankenstein“, one of the funniest movies of all time,  and there is a joke in it about “elevate me” (go to this page and search for “elevate”), so I created the “Elevate-Me” function:

function Elevate-Me ()
    echo "Inga:            ""Now? Right here?"""
    echo "Dr Frankenstein: ""Yes, yes.  Raise the platform"""
    echo "Inga:            ""Oh. Ze platform. Oh, zat, yah, yah ... yes"""
    Start-Process "$psHome\powershell.exe" -Verb Runas

Just add it to your profile and let the elevating begin 🙂

BTW: I know “Elevate” is not an approved verb, but it’s worth it for the homage to the brilliance of Mel & Gene (and Teri).


Written by gsdwriter

April 20, 2012 at 8:00 am

Posted in Humor, Powershell, Tools