Windows PowerShell is an extensible command line interface shell and associated scripting language from Microsoft. To implement you own specialist functions you can use cmdlets for enhancing PowerShell. Cmdlets are specialized .NET classes, which the PowerShell runtime instantiates and invokes when they are run.
For building your own cmdlets I’ve found C# and VB.NET cmdlet Templates in the web.
(Extract the ZIP File and you should find 2 vsi files. One for C# and one for VB.NET. They are working well with Visual Studio 2008.)

If you now go to Visual Studio and create a new project select Windows Powershell Template as the project template.


Right-click your project and choose, add then New Item. From the list of items choose Windows PowerShell PSCmdlet. This should be the default choice for cmdlets.

Microsoft describes how to extend Windows PowerShell with custom commands in the following MSDN article.
After building our solution we need to install assembly with the InstallUtil tool. Open a Visual Studio cmd prompt, navigate to the bin\debug folder of your solution and run:

InstallUtil yourassemblyname.dll
Next load Windows PowerShell and type:

Get-PSSnapIn -registered
(which should list your snapin along with any other snapins currently registered.)
Next enter:

Add-PSSnapIn yoursnapinname
(this will load your snapin)
You should now be able to call your new functions in PowerShell.

In the next couple of weeks (if I will have time) I’d like to develop a cmdlet which allows you to do basic operation tasks within a Citrix Presentation Server or XenApp farm. Things like: list all sessions, get farm name, logoff idle session, etc.
Have fun