PowerShell Project In Visual Studio

PowerShell scripting is useful for various Windows, .NET and SharePoint projects. Usually, we write script in any editor (text editors, PowerGUI etc) and save as PowerShell script file (.ps1). This script can be executed on Windows PowerShell console.

PowerGUI Script editor

For most developers, PowerGUI Script editor is the most popular editor where we can develop and debug PS scripts.

PowerGUI Script editor

In this article I’ll explain how we can create a PowerShell project in Visual Studio:

  • To enable PS in Visual studio, first thing we need is to download the PowerShell Tool Extension for visual studio. The following are the links:

  • Next is to install this on your respective machine, make sure Visual Studio is already closed before running the installer.

    Installation

  • After Installation is completed, open Visual Studio.

  • Go to File, New, then Project.

    New Project

  • Select PowerShell from Templates and then select “PowerShell Script Project” as project type. Provide Project Name and hit OK.

    Select PowerShell from Templates

  • PowerShell project will be created with a ps1 file ‘Script.ps1’ added to it. You can rename this default script and add more scripts or modules. Right Click on Project, Add, New Item, then PowerShell Script or Module (as required).

    PowerShell project

  • Finally your project will look similar to this:

    project

  • You can develop & debug script in visual studio just like other .NET projects.

Reference: PowerGUI Documentation