@@ -4,39 +4,50 @@ Area: languages
4
4
TOCTitle : PowerShell
5
5
ContentId : 8688bb6d-793e-4a37-aed2-5af4cfe89940
6
6
PageTitle : PowerShell editing with Visual Studio Code
7
- DateApproved : 02/06 /2025
7
+ DateApproved : 02/20 /2025
8
8
MetaDescription : Learn about using PowerShell in Visual Studio Code
9
9
---
10
10
# PowerShell in Visual Studio Code
11
11
12
- [ PowerShell] [ 20 ] is a task-based command-line shell and scripting language built on [ .NET] [ 19 ] that
12
+ [ PowerShell] [ 24 ] is a task-based command-line shell and scripting language built on [ .NET] [ 23 ] that
13
13
provides a powerful toolset for administrators on any platform.
14
14
15
- The Microsoft [ PowerShell] [ 27 ] extension for Visual Studio Code (VS Code) provides rich language
15
+ The Microsoft [ PowerShell] [ 31 ] extension for Visual Studio Code (VS Code) provides rich language
16
16
support and capabilities such as syntax completions, definition tracking, and linting for
17
- PowerShell. The extension should work anywhere VS Code itself and PowerShell Core 7.2 or higher is
18
- [ supported] [ 14 ] . For Windows PowerShell, only version 5.1 is supported and only on a best-effort
19
- basis. PowerShell Core 6, 7.0, and 7.1 have reached end-of-support. We test the following
20
- configurations:
17
+ PowerShell. The extension should work anywhere VS Code is supported using supported versions of
18
+ [ PowerShell 7] [ 17 ] .
21
19
22
- - ** Windows Server 2022** with Windows PowerShell 5.1 and PowerShell 7.2
23
- - ** Windows Server 2019** with Windows PowerShell 5.1 and PowerShell 7.2
24
- - ** macOS 11** with PowerShell Core 7.2
25
- - ** Ubuntu 20.04** with PowerShell Core 7.2
20
+ Support for Windows PowerShell 5.1 is provided on a best effort basis. [ .NET Framework 4.8] [ 18 ] or
21
+ higher is required.
22
+
23
+ [ VS Code Remote Development] [ 13 ] Environments, including [ Github Codespaces] [ 19 ] and
24
+ [ VS Code Server] [ 14 ] are supported.
25
+
26
+ > [ !IMPORTANT]
27
+ > [ Visual Studio Code for the Web] [ 12 ] is only supported for limited functionality such as basic
28
+ > syntax highlighting, as the PowerShell engine can't run in this environment.
29
+
30
+ We actively test the following configurations:
31
+
32
+ - ** Windows Server 2022** with Windows PowerShell 5.1 and PowerShell 7+
33
+ - ** macOS 14.7** with PowerShell 7+
34
+ - ** Ubuntu 22.04** with PowerShell 7+
35
+
36
+ On Windows, we also test with and without Constrained Language Mode enabled.
26
37
27
38
## Installing the PowerShell extension
28
39
29
40
The PowerShell extension can be installed from the Visual Studio Code Marketplace by clicking the
30
- [ Install Button] [ 41 ] . You can also install the PowerShell extension from within VS Code by opening
41
+ [ Install Button] [ 44 ] . You can also install the PowerShell extension from within VS Code by opening
31
42
the ** Extensions** view with keyboard shortcut ` kb(workbench.view.extensions) ` , typing _ PowerShell_ ,
32
43
and selecting the PowerShell extension:
33
44
34
- ![ PowerShell extension] [ 37 ]
45
+ ![ PowerShell extension] [ 40 ]
35
46
36
47
## Major features
37
48
38
- - [ Syntax highlighting] [ 15 ]
39
- - Advanced built-in [ code snippets] [ 06 ]
49
+ - [ Syntax highlighting] [ 20 ]
50
+ - Advanced built-in [ code snippets] [ 08 ]
40
51
- [ IntelliSense] [ 05 ] for cmdlets and more
41
52
- [ Problems] [ 09 ] reported by [ PowerShell Script Analyzer] [ 11 ]
42
53
- [ Go to Definition] [ 02 ] of cmdlets, variables, classes and more
@@ -45,21 +56,21 @@ and selecting the PowerShell extension:
45
56
- Symbol-based [ Outline View] [ 10 ]
46
57
- Run selected PowerShell code in current terminal using ` kbstyle(F8) `
47
58
- Launch online help for the symbol under the cursor using ` kbstyle(Ctrl + F1) `
48
- - PowerShell [ Debugger] [ 25 ] integration
59
+ - PowerShell [ Debugger] [ 29 ] integration
49
60
- An Extension Terminal that can interact with the debugger (try ` Set-PSBreakpoint ` !)
50
- - PowerShell ISE theme findable in the [ theme picker] [ 08 ]
61
+ - PowerShell ISE theme available in the [ theme picker] [ 07 ]
51
62
- Also try ISE mode using ` kb(workbench.action.showCommands) ` then search for "Enable ISE Mode"
52
63
53
64
### Debugging
54
65
55
66
The PowerShell extension uses the built-in [ debugging interface] [ 01 ] of VS Code to allow for
56
67
debugging of PowerShell scripts and modules. For more information about debugging PowerShell, see
57
- [ Using VS Code] [ 25 ] .
68
+ [ Using VS Code] [ 29 ] .
58
69
59
70
### Multi-version support
60
71
61
72
You can configure the PowerShell extension to use any supported version of PowerShell installed on
62
- your machine by following [ these instructions] [ 24 ] .
73
+ your machine by following [ these instructions] [ 28 ] .
63
74
64
75
Or run the ** PowerShell: Show Session Menu** command from the Command Palette
65
76
(` kb(workbench.action.showCommands) ` ).
@@ -73,22 +84,22 @@ CodeLens features include:
73
84
74
85
- Pester ** Run tests** and ** Debug tests** .
75
86
76
- ![ Pester CodeLens Integration] [ 36 ]
87
+ ![ Pester CodeLens Integration] [ 39 ]
77
88
78
89
- Pester symbol support
79
90
80
- ![ CodeLens Pester Symbol Support] [ 34 ]
91
+ ![ CodeLens Pester Symbol Support] [ 38 ]
81
92
82
93
- Function, variable, class, and other symbol references
83
94
84
95
CodeLens reference support shows the number of times a symbol is referenced within your
85
96
code and allows you to jump to specific references.
86
97
87
- ![ CodeLens Function Reference Support] [ 33 ]
98
+ ![ CodeLens Function Reference Support] [ 37 ]
88
99
89
100
### PSScriptAnalyzer integration
90
101
91
- [ PSScriptAnalyzer] [ 26 ] is a PowerShell module that provides a static source code checker for modules
102
+ [ PSScriptAnalyzer] [ 30 ] is a PowerShell module that provides a static source code checker for modules
92
103
and scripts. ** PSScriptAnalyzer** has rules that verify the quality of PowerShell code. These rules
93
104
are based on PowerShell best practices identified by the PowerShell Team and the community.
94
105
** PSScriptAnalyzer** generates diagnostic records (errors and warnings) to inform users about
@@ -106,49 +117,38 @@ To disable **PSScriptAnalyzer**, open your settings (`kb(workbench.action.openSe
106
117
** Extensions** , select the ** PowerShell** extension, and deselect the checkbox for ** Script
107
118
Analysis: Enable** (` powershell.scriptAnalysis.enable ` ).
108
119
109
- ![ PSScriptAnalyzer Settings] [ 39 ]
120
+ ![ PSScriptAnalyzer Settings] [ 42 ]
110
121
111
122
** PSScriptAnalyzer** also provides code formatting. You can invoke automatic document formatting
112
123
with the ** Format Document** command or the (` kb(editor.action.formatDocument) ` ) keyboard shortcut.
113
124
114
125
### Pester integration
115
126
116
- [ Pester] [ 29 ] is a framework for running unit tests to execute and Windows PowerShell 5.1 comes with
127
+ [ Pester] [ 33 ] is a framework for running unit tests to execute and Windows PowerShell 5.1 comes with
117
128
** Pester** 3.40 preinstalled. To update ** Pester** or to install the latest version on other
118
- platforms, follow the [ Pester installation instructions] [ 30 ] .
119
-
120
- ### Plaster integration
121
-
122
- [ Plaster] [ 16 ] is a template-based file and project generator written in PowerShell. Its purpose is
123
- to streamline the creation of PowerShell module projects, Pester tests, DSC Configurations and more.
124
-
125
- The PowerShell extension allows the creation of new Plaster projects using the ** PowerShell: Create
126
- New Project from Plaster Template** command from the Command Palette
127
- (` kb(workbench.action.showCommands) ` ).
128
-
129
- ![ Plaster Project] [ 35 ]
129
+ platforms, follow the [ Pester installation instructions] [ 34 ] .
130
130
131
131
## PowerShell extension settings
132
132
133
- You can customize VS Code [ settings] [ 07 ] from the ** File** > ** Preferences** > ** Settings** menu item.
133
+ You can customize VS Code [ settings] [ 06 ] from the ** File** > ** Preferences** > ** Settings** menu item.
134
134
135
135
You can also select the gear icon located in the lower left corner of the Activity Bar.
136
136
137
- ![ codeGear] [ 32 ]
137
+ ![ codeGear] [ 36 ]
138
138
139
139
You can also use the keyboard shortcut ` kb(workbench.action.openSettings) ` to open your settings.
140
140
You can still open the ` settings.json ` file using ** Preferences: Open User Settings (JSON)** command from
141
141
the Command Palette (` kb(workbench.action.showCommands) ` ) or by changing the default settings editor
142
142
with the ` "workbench.settings.editor" ` setting.
143
143
144
- Go to [ User and Workspace settings] [ 07 ] for more information on configuring VS Code settings.
144
+ Go to [ User and Workspace settings] [ 06 ] for more information on configuring VS Code settings.
145
145
146
146
### Types.ps1xml and Format.ps1xml files
147
147
148
148
PowerShell ` .ps1xml ` files are used to extend the type system and define output formatting. For more
149
- information on these files, see the official PowerShell documentation on [ Types.ps1xml] [ 22 ] and
150
- [ Format.ps1xml] [ 21 ] . You can get IntelliSense features when authoring ` .ps1xml ` files by installing
151
- the [ XML extension by Red Hat] [ 28 ] . After installing, add this configuration to your user settings:
149
+ information on these files, see the official PowerShell documentation on [ Types.ps1xml] [ 26 ] and
150
+ [ Format.ps1xml] [ 25 ] . You can get IntelliSense features when authoring ` .ps1xml ` files by installing
151
+ the [ XML extension by Red Hat] [ 32 ] . After installing, add this configuration to your user settings:
152
152
153
153
``` json
154
154
"xml.fileAssociations" : [
@@ -192,19 +192,19 @@ code (Get-ChildItem ~\.vscode\extensions\ms-vscode.PowerShell-*\examples)[-1]
192
192
You can also open the examples from the Command Palette (` kb(workbench.action.showCommands) ` ) with
193
193
the ** PowerShell: Open Examples Folder** command.
194
194
195
- ![ Open PowerShell Examples] [ 40 ]
195
+ ![ Open PowerShell Examples] [ 43 ]
196
196
197
197
## Additional resources
198
198
199
- There are more detailed articles in the PowerShell documentation. Start with [ Using VS Code] [ 23 ] .
199
+ There are more detailed articles in the PowerShell documentation. Start with [ Using VS Code] [ 27 ] .
200
200
201
- Check out the [ troubleshooting guide] [ 17 ] for answers to common questions.
201
+ Check out the [ troubleshooting guide] [ 21 ] for answers to common questions.
202
202
203
203
For more information on debugging, check out the _ Hey, Scripting Guy!_ two-part blog post series
204
- written by [ @keithHill ] [ 31 ] on debugging with the PowerShell extension:
204
+ written by [ @keithHill ] [ 35 ] on debugging with the PowerShell extension:
205
205
206
- - [ Debugging PowerShell script in Visual Studio Code - Part 1] [ 12 ]
207
- - [ Debugging PowerShell script in Visual Studio Code - Part 2] [ 13 ]
206
+ - [ Debugging PowerShell script in Visual Studio Code - Part 1] [ 15 ]
207
+ - [ Debugging PowerShell script in Visual Studio Code - Part 2] [ 16 ]
208
208
209
209
## Testing new features and providing feedback
210
210
@@ -215,49 +215,52 @@ by using the **Switch to Release Version** button that will appear. You can also
215
215
to other versions of the extension using the arrow next to the ** Uninstall** button and
216
216
choosing ** Install Another Version...** .
217
217
218
- ![ Screenshot showing the button to switch to a pre-release version.] [ 38 ]
218
+ ![ Screenshot showing the button to switch to a pre-release version.] [ 41 ]
219
219
220
- If you find a bug, [ open an issue] [ 18 ] and revert to the stable version while we fix it.
220
+ If you find a bug, [ open an issue] [ 22 ] and revert to the stable version while we fix it.
221
221
222
222
<!-- link references -->
223
223
[ 01 ] : /docs/editor/debugging
224
224
[ 02 ] : /docs/editor/editingevolved#_go-to-definition
225
225
[ 03 ] : /docs/editor/editingevolved#_open-symbol-by-name
226
226
[ 04 ] : /docs/editor/editingevolved#_reference-information
227
227
[ 05 ] : /docs/editor/intellisense
228
- [ 06 ] : /docs/editor/userdefinedsnippets
229
- [ 07 ] : /docs/editor/settings
230
- [ 08 ] : /docs/editor/themes
228
+ [ 06 ] : /docs/editor/settings
229
+ [ 07 ] : /docs/editor/themes
230
+ [ 08 ] : /docs/editor/userdefinedsnippets
231
231
[ 09 ] : /docs/getstarted/tips-and-tricks#_errors-and-warnings
232
232
[ 10 ] : /docs/getstarted/userinterface#_outline-view
233
233
[ 11 ] : http://github.com/PowerShell/PSScriptAnalyzer
234
- [ 12 ] : https://devblogs.microsoft.com/scripting/debugging-powershell-script-in-visual-studio-code-part-1/
235
- [ 13 ] : https://devblogs.microsoft.com/scripting/debugging-powershell-script-in-visual-studio-code-part-2/
236
- [ 14 ] : https://docs.microsoft.com/en-us/powershell/scripting/powershell-support-lifecycle
237
- [ 15 ] : https://github.com/PowerShell/EditorSyntax
238
- [ 16 ] : https://github.com/PowerShell/Plaster
239
- [ 17 ] : https://github.com/PowerShell/vscode-powershell/blob/main/docs/troubleshooting.md#troubleshooting-powershell-extension-issues
240
- [ 18 ] : https://github.com/PowerShell/vscode-powershell/issues/new/choose
241
- [ 19 ] : https://learn.microsoft.com/dotnet
242
- [ 20 ] : https://learn.microsoft.com/powershell/
243
- [ 21 ] : https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_format.ps1xml
244
- [ 22 ] : https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_types.ps1xml
245
- [ 23 ] : https://learn.microsoft.com/powershell/scripting/dev-cross-plat/vscode/using-vscode
246
- [ 24 ] : https://learn.microsoft.com/powershell/scripting/dev-cross-plat/vscode/using-vscode#choosing-a-version-of-powershell-to-use-with-the-extension
247
- [ 25 ] : https://learn.microsoft.com/powershell/scripting/dev-cross-plat/vscode/using-vscode#debugging-with-visual-studio-code
248
- [ 26 ] : https://learn.microsoft.com/powershell/utility-modules/psscriptanalyzer/overview
249
- [ 27 ] : https://marketplace.visualstudio.com/items?itemName=ms-vscode.PowerShell
250
- [ 28 ] : https://marketplace.visualstudio.com/items?itemName=redhat.vscode-xml
251
- [ 29 ] : https://pester.dev/
252
- [ 30 ] : https://pester.dev/docs/introduction/installation
253
- [ 31 ] : https://twitter.com/r_keith_hill
254
- [ 32 ] : images/powershell/codeGear.png
255
- [ 33 ] : images/powershell/codeLensFuncRef.gif
256
- [ 34 ] : images/powershell/codeLensPesterSymbol.gif
257
- [ 35 ] : images/powershell/cpPlasterCommand.png
258
- [ 36 ] : images/powershell/pesterCodeLens.png
259
- [ 37 ] : images/powershell/PowerShellExtension.png
260
- [ 38 ] : images/powershell/prerelease-switch.png
261
- [ 39 ] : images/powershell/pssaExtensionSetting.png
262
- [ 40 ] : images/powershell/pwshExamples.png
263
- [ 41 ] : vscode:extension/ms-vscode.PowerShell
234
+ [ 12 ] : https://code.visualstudio.com/docs/editor/vscode-web
235
+ [ 13 ] : https://code.visualstudio.com/docs/remote/remote-overview
236
+ [ 14 ] : https://code.visualstudio.com/docs/remote/vscode-server
237
+ [ 15 ] : https://devblogs.microsoft.com/scripting/debugging-powershell-script-in-visual-studio-code-part-1/
238
+ [ 16 ] : https://devblogs.microsoft.com/scripting/debugging-powershell-script-in-visual-studio-code-part-2/
239
+ [ 17 ] : https://docs.microsoft.com/en-us/powershell/scripting/powershell-support-lifecycle
240
+ [ 18 ] : https://dotnet.microsoft.com/download/dotnet-framework
241
+ [ 19 ] : https://github.com/features/codespaces
242
+ [ 20 ] : https://github.com/PowerShell/EditorSyntax
243
+ [ 21 ] : https://github.com/PowerShell/vscode-powershell/blob/main/docs/troubleshooting.md#troubleshooting-powershell-extension-issues
244
+ [ 22 ] : https://github.com/PowerShell/vscode-powershell/issues/new/choose
245
+ [ 23 ] : https://learn.microsoft.com/dotnet
246
+ [ 24 ] : https://learn.microsoft.com/powershell/
247
+ [ 25 ] : https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_format.ps1xml
248
+ [ 26 ] : https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_types.ps1xml
249
+ [ 27 ] : https://learn.microsoft.com/powershell/scripting/dev-cross-plat/vscode/using-vscode
250
+ [ 28 ] : https://learn.microsoft.com/powershell/scripting/dev-cross-plat/vscode/using-vscode#choosing-a-version-of-powershell-to-use-with-the-extension
251
+ [ 29 ] : https://learn.microsoft.com/powershell/scripting/dev-cross-plat/vscode/using-vscode#debugging-with-visual-studio-code
252
+ [ 30 ] : https://learn.microsoft.com/powershell/utility-modules/psscriptanalyzer/overview
253
+ [ 31 ] : https://marketplace.visualstudio.com/items?itemName=ms-vscode.PowerShell
254
+ [ 32 ] : https://marketplace.visualstudio.com/items?itemName=redhat.vscode-xml
255
+ [ 33 ] : https://pester.dev/
256
+ [ 34 ] : https://pester.dev/docs/introduction/installation
257
+ [ 35 ] : https://twitter.com/r_keith_hill
258
+ [ 36 ] : images/powershell/codeGear.png
259
+ [ 37 ] : images/powershell/codeLensFuncRef.gif
260
+ [ 38 ] : images/powershell/codeLensPesterSymbol.gif
261
+ [ 39 ] : images/powershell/pesterCodeLens.png
262
+ [ 40 ] : images/powershell/PowerShellExtension.png
263
+ [ 41 ] : images/powershell/prerelease-switch.png
264
+ [ 42 ] : images/powershell/pssaExtensionSetting.png
265
+ [ 43 ] : images/powershell/pwshExamples.png
266
+ [ 44 ] : vscode:extension/ms-vscode.PowerShell
0 commit comments