LoginSignup
17
31

More than 5 years have passed since last update.

Visual Studio CodeでPowerShell開発環境を整える

Posted at

この記事では、Visual Studio Codeを利用して、PowerShellの開発に必要となる機能をセットアップする方法をまとめます。多くの人が普通のテキストエディタや、PowerShell ISEを利用していると思います。Visual Studio Codeを利用すればPowerShellのコードはもちろん書けますし、拡張機能をインストールすることによりデバッグ、コード補完等のPowerShell ISEと同等の機能を持たせることが可能です。
なお本記事を執筆した時点でのVisual Studio Codeのバージョンは 1.10.2 です。

1. プラグインの導入

下記のPowerShell拡張用のプラグインはコーディングに必要な一通りの機能(デバッグ、インテリセンス等、詳細は後述)が揃っています。

プラグイン 名前とリンク 用途
image PowerShell This extension provides rich PowerShell language support for Visual Studio Code. Now you can write and debug PowerShell scripts using the excellent IDE-like interface that Visual Studio Code provides.

Visual Studio CodeでCtrl+Pでコマンドパレットを開き、下記のコマンドを実行し、プラグインを検索します。

ext install PowerShell

拡張機能ペインから「PowerShell」を選択し、「インストール」をクリック。これでVisual Studio CodeにPowerShellを開発するために必要と思われる機能が全て導入されます。

2. 機能紹介

本プラグインを導入することで使用できる機能について紹介します。

インテリセンス(コード補完)

コマンドを補完してくれたり、
image
コマンドのパラメータ候補を表示してくれたりします。
image

端末(Terminal)の自動表示

編集中のファイルがPowerShellファイル(*.ps1)の場合、画面下部にTerminalが勝手に起動します。
image

デバッグの実行

ブレイクポイントの設置、F5デバッグ実行、ウォッチ式、変数の表示など、PowerShell ISEと同じレベルの操作が可能です。
image

その他の機能

前述のプラグインのページから、機能一覧を転記しておきます。

  • Syntax highlighting
  • Code snippets
  • IntelliSense for cmdlets and more
  • Rule-based analysis provided by PowerShell Script Analyzer
  • Go to Definition of cmdlets and variables
  • Find References of cmdlets and variables
  • Document and workspace symbol discovery
  • Run selected selection of PowerShell code using F8
  • Launch online help for the symbol under the cursor using Ctrl+F1
  • Local script debugging and basic interactive console support!

2. おわりに

今回はPowerShellを対象としました。Visual Studio Codeは多くの言語をサポートしているリッチテキストエディタですよね。何をするにしてもこれ一つで十分かも。今後ももっと他の活用方法を探してみたいと思います。

17
31
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
31