PowerShell Code Generator

Brings rich PowerShell functionalities into VS Templating. You can access the file system, the registry, and many other PowerShell features to templating. You can also run PowerShell cmdlets, import modules and more.


  • Integrated PowerShell
  • Enables VS automation object DTE (exposed as variable “$dte” in PowerShell)
  • Create any file type by setting the $extension variable
  • Supports a profile through the $PSCGProfile variable

How to install PowerShell Code Generator

  1. Download the zip
  2. Unzip
  3. Run .\Install-PSCodeGenerator.ps1 at the PowerShell console prompt
  4. Copies the templates for use in Visual Studio
  5. Registers the the PowerShell code generator custom tool

How to use PSCodeGenerator

These are the manual steps needed to enable the PowerShell Code Generator custom tool. Or you can use the templates that get installed.
  • Start VS 2010
  • Create a Console project
  • Add a text file and name it test.ps1
    • The file requires a .ps1 extension in order to work
  • Select this file in the Solution Explorer.
  • Go to its properties and set the ‘Custom Tool’ property to PSCodeGenerator (case insensitive)
Properties Window
  • You should see this in the Solution Explorer if all is well
Solution Explorer
  • Type in the test.ps1 file. Save the file or build and the test.cs file should get populated.

1..2 | % {
public class Test$($_) {


VS 2010 PowerShell Templates

Here a the templates currently included.
PowerShell Templates




// <auto-generated>
// Generated at $(Get-Date)
// </auto-generated>


Dynamic code generation

Static SQL Example


create procedure Products_Delete
    @ProductID int
    delete from Products
    where ProductID = @ProductID


SQL Generation

Last edited Jun 15, 2010 at 12:57 AM by dfinke, version 20


koaunglay Aug 1, 2014 at 12:10 PM 
Can I use adbshell command in c# with powershell?