Visual Studio Code Configuration
This guide provides comprehensive instructions for configuring Visual Studio Code as a powerful PowerShell development environment. The configuration focuses on PowerShell and complementary technologies for enhanced productivity.
Extensions and Installation
VS Code is designed to be very extensible. There are a few extensions that we will install to make it possible to develop PowerShell code.
Installing Extensions
Extensions can be installed through multiple methods:
Via Extensions View:
- Open Extensions view with
Ctrl+Shift+X
- Search for the extension name
- Click Install
Via Command Line:
# Install PowerShell extension
code --install-extension ms-vscode.PowerShell
# Install additional recommended extensions
code --install-extension ms-vscode.vscode-json
code --install-extension redhat.vscode-yaml
code --install-extension streetsidesoftware.code-spell-checker
code --install-extension davidanson.vscode-markdownlint
code --install-extension eamodio.gitlens
Configuring Extensions
To configure an extension:
- Click the Settings Sprocket in the lower left-hand corner
- Select Settings from the menu
- Select the User tab at the top of the screen
- Scroll down and expand Extensions in the left pane
- Click on the extension and update settings in the right pane as needed
Essential Extensions for PowerShell Development
The following extensions are essential for PowerShell development in VS Code:
Core Extensions
PowerShell Extension
Publisher: Microsoft
ID: ms-vscode.PowerShell
The Microsoft PowerShell extension provides comprehensive language support including:
- Syntax highlighting and IntelliSense
- Code completion and parameter hints
- Definition tracking and symbol navigation
- Integrated PowerShell console
- Debugging capabilities
- Script analysis with PSScriptAnalyzer
- Code formatting and refactoring
Installation:
code --install-extension ms-vscode.PowerShell
GitLens Extension
Publisher: GitKraken
ID: eamodio.gitlens
Enhances Git capabilities within VS Code:
- Line-by-line Git blame annotations
- Commit and file history
- Repository and branch insights
- Advanced Git visualization
Additional Recommended Extensions
Extension | Publisher | Purpose |
---|---|---|
JSON | Microsoft | JSON file support and validation |
YAML | Red Hat | YAML syntax support |
Code Spell Checker | Street Side Software | Spell checking for code and comments |
markdownlint | David Anson | Markdown linting and formatting |
GitHub Copilot | GitHub | AI-powered code completion |
VS Code Configuration for PowerShell
PowerShell Extension Settings
Configure the PowerShell extension for optimal development experience:
Recommended Settings
Add these settings to your VS Code settings.json
file:
{
// PowerShell extension configuration
"powershell.codeFormatting.preset": "OTBS",
"powershell.codeFormatting.openBraceOnSameLine": false,
"powershell.codeFormatting.newLineAfterOpenBrace": true,
"powershell.codeFormatting.newLineAfterCloseBrace": true,
"powershell.codeFormatting.addWhitespaceAroundPipe": true,
"powershell.codeFormatting.autoCorrectAliases": true,
"powershell.codeFormatting.avoidSemicolonsAsLineTerminators": true,
"powershell.codeFormatting.trimWhitespaceAroundPipe": true,
"powershell.codeFormatting.useCorrectCasing": true,
"powershell.scriptAnalysis.enable": true,
"powershell.integratedConsole.showOnStartup": false,
"powershell.debugging.createTemporaryIntegratedConsole": true,
// General editor settings for PowerShell
"editor.tabSize": 4,
"editor.insertSpaces": true,
"editor.detectIndentation": false,
"editor.wordWrap": "on",
"editor.formatOnSave": true,
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true
}
PowerShell Extension Configuration Summary
Setting | Recommended Value | Description |
---|---|---|
Code Folding | Enable | Allows collapsing code blocks |
Add Whitespace Around Pipe | Enable | Improves readability of pipeline commands |
Auto Correct Aliases | Enable | Expands aliases to full cmdlet names |
Avoid Semicolons As Line Terminators | Enable | Follows PowerShell best practices |
Open Brace On Same Line | Disable | Places opening braces on new lines |
Trim Whitespace Around Pipe | Enable | Removes extra spaces around pipes |
Use Correct Casing | Enable | Corrects cmdlet and parameter casing |
Additional Extension Configuration
GitHub Copilot
If you have a GitHub Copilot subscription, this extension provides AI-powered code completion:
code --install-extension github.copilot
markdownlint
For documentation and README files, install markdownlint:
code --install-extension davidanson.vscode-markdownlint
Configure markdownlint with these settings:
{
"markdownlint.config": {
"MD013": { "line_length": 120 },
"MD033": false,
"MD041": false
}
}
Custom Code Snippets
VS Code provides the ability to create custom code snippets for frequently used code patterns. This is particularly useful for PowerShell development where you might have standard function templates or common script patterns.
Quick Overview
Benefits of using snippets:
- Faster code development with templates
- Consistent code patterns across projects
- Reduced typing for repetitive structures
- Customizable placeholders and tab stops
Access snippet configuration:
- Open Command Palette (
Ctrl+Shift+P
) - Type "Configure User Snippets"
- Select the language (e.g., "powershell.json")
Comprehensive Snippet Guide
For detailed information on creating, configuring, and using snippets, including:
- Advanced PowerShell function templates
- Administrative automation snippets
- Documentation and knowledge base templates
- Best practices and advanced features
See the dedicated guide: VS Code Snippets for PowerShell
Advanced Configuration
Workspace Settings
For project-specific settings, create a .vscode/settings.json
file in your project root:
{
// PowerShell-specific workspace settings
"powershell.scriptAnalysis.settingsPath": ".vscode/PSScriptAnalyzerSettings.psd1",
"powershell.codeFormatting.preset": "Custom",
"powershell.developer.bundledModulesPath": "./modules",
// File associations
"files.associations": {
"*.ps1xml": "xml",
"*.psd1": "powershell",
"*.psm1": "powershell"
},
// Explorer settings
"files.exclude": {
"**/bin": true,
"**/obj": true,
"**/.vs": true
}
}
Task Configuration
Create a .vscode/tasks.json
file for common PowerShell tasks:
{
"version": "2.0.0",
"tasks": [
{
"label": "Run PowerShell Script",
"type": "shell",
"command": "pwsh",
"args": ["-File", "${file}"],
"group": "build",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
}
},
{
"label": "Analyze Script",
"type": "shell",
"command": "pwsh",
"args": ["-Command", "Invoke-ScriptAnalyzer -Path '${file}' -Severity Warning,Error"],
"group": "test",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
}
}
]
}
Debug Configuration
Create a .vscode/launch.json
file for debugging:
{
"version": "0.2.0",
"configurations": [
{
"name": "PowerShell: Launch Current File",
"type": "PowerShell",
"request": "launch",
"script": "${file}",
"cwd": "${workspaceFolder}"
},
{
"name": "PowerShell: Interactive Session",
"type": "PowerShell",
"request": "launch",
"cwd": "${workspaceFolder}"
}
]
}
References and Additional Resources
Official Documentation
- VS Code PowerShell Extension - Official extension page
- VS Code Snippets Documentation - Complete guide to creating custom snippets
- VS Code Settings Reference - User and workspace settings guide
- PowerShell Extension Documentation - Official PowerShell development guide
Configuration Resources
- PSScriptAnalyzer Rules - Complete list of analysis rules
- VS Code Tasks Documentation - Task automation guide
- PowerShell Best Practices - Community style guide
- VS Code Debugging - Debugging configuration and usage
Extension Resources
- GitLens Extension - Enhanced Git capabilities
- GitHub Copilot - AI-powered code completion
- markdownlint - Markdown linting
- Code Spell Checker - Spell checking for code
Community Resources
- PowerShell Community - PowerShell GitHub repository
- VS Code PowerShell Issues - Extension support and issues
- r/PowerShell - PowerShell community on Reddit
- PowerShell.org - PowerShell community hub
Last updated: {{ site.time | date: "%Y-%m-%d" }}