Add VSCode extensions and PowerShell 7 integration setup

- Added function to install VSCode extensions via command line
- Install PowerShell extension for better PowerShell support in VSCode
- Install GitLens and Git Graph extensions for enhanced Git experience
- Configure VSCode to use PowerShell 7 as default terminal
- Update progress tracking to include extension installation step
- Add extension results to installation summary
This commit is contained in:
Bjarke Sporring
2026-01-14 16:49:35 +01:00
parent 6d2e099eb4
commit f55cb444e7

View File

@@ -257,12 +257,13 @@ $results = @{
PowerShell = $false
Git = $false
VSCode = $false
VSCodeExtensions = $false
Python = $null # null = not attempted, true = success, false = failed
WindowsTerminal = $null
}
# Progress tracking
$totalSteps = 3 # Required installations
$totalSteps = 4 # Required installations + extensions
$currentStep = 0
Write-Host "`nStarting installation..." -ForegroundColor Cyan
@@ -280,6 +281,91 @@ function Write-ProgressIndicator {
Write-Progress -Activity $Activity -Status $Status -PercentComplete $PercentComplete
}
function Install-VSCodeExtension {
param(
[string]$ExtensionId,
[string]$ExtensionName
)
Write-Host " Installing VSCode extension: $ExtensionName" -ForegroundColor Cyan
try {
# Refresh environment to ensure code command is available
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
$result = & code --install-extension $ExtensionId 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Success "VSCode extension '$ExtensionName' installed successfully"
return $true
}
else {
Write-Warning "Failed to install VSCode extension '$ExtensionName'"
Write-Host " You can install it manually later: Ctrl+Shift+X → Search '$ExtensionName'" -ForegroundColor Gray
return $false
}
}
catch {
Write-Warning "Could not install VSCode extension '$ExtensionName`: $_"
Write-Host " You can install it manually later: Ctrl+Shift+X → Search '$ExtensionName'" -ForegroundColor Gray
return $false
}
}
function Set-VSCodePowerShellIntegration {
Write-Host " Configuring PowerShell 7 integration with VSCode..." -ForegroundColor Cyan
try {
# Set PowerShell 7 as the default terminal in VSCode
$vscodeSettingsPath = Join-Path $env:APPDATA "Code\User\settings.json"
$vscodeSettingsDir = Split-Path $vscodeSettingsPath -Parent
# Create directory if it doesn't exist
if (-not (Test-Path $vscodeSettingsDir)) {
New-Item -Path $vscodeSettingsDir -ItemType Directory -Force | Out-Null
}
# Read existing settings or create new
if (Test-Path $vscodeSettingsPath) {
$settings = Get-Content $vscodeSettingsPath -Raw | ConvertFrom-Json
}
else {
$settings = @{}
}
# Set PowerShell 7 as default terminal
if (-not $settings.PSObject.Properties.Name -contains "terminal.integrated.defaultProfile.windows") {
$settings | Add-Member -NotePropertyName "terminal.integrated.defaultProfile.windows" -NotePropertyValue "PowerShell"
}
else {
$settings."terminal.integrated.defaultProfile.windows" = "PowerShell"
}
# Add terminal profiles if not present
if (-not $settings.PSObject.Properties.Name -contains "terminal.integrated.profiles.windows") {
$profiles = @{
"PowerShell" = @{
"source" = "PowerShell"
"icon" = "terminal-powershell"
"path" = "pwsh.exe"
}
}
$settings | Add-Member -NotePropertyName "terminal.integrated.profiles.windows" -NotePropertyValue $profiles
}
# Save settings
$settings | ConvertTo-Json -Depth 10 | Set-Content $vscodeSettingsPath
Write-Success "VSCode configured to use PowerShell 7 as default terminal"
return $true
}
catch {
Write-Warning "Could not configure VSCode PowerShell integration automatically"
Write-Host " You can configure it manually in VSCode: Ctrl+Shift+P → Terminal: Select Default Profile → PowerShell" -ForegroundColor Gray
return $false
}
}
#region Required Installations
# Install PowerShell 7
@@ -310,12 +396,36 @@ if ($results.Git) {
# Install Visual Studio Code
$currentStep++
Write-ProgressIndicator -Activity "Installing Required Tools" -Status "Installing Visual Studio Code (3/3)" -PercentComplete (($currentStep / $totalSteps) * 100)
Write-ProgressIndicator -Activity "Installing Required Tools" -Status "Installing Visual Studio Code (3/4)" -PercentComplete (($currentStep / $totalSteps) * 100)
$results.VSCode = Install-Package `
-Name "Visual Studio Code" `
-WingetId "Microsoft.VisualStudioCode" `
-CheckCommand "code"
# Install VSCode Extensions and configure PowerShell integration
if ($results.VSCode) {
$currentStep++
Write-ProgressIndicator -Activity "Installing Required Tools" -Status "Installing VSCode Extensions (4/4)" -PercentComplete (($currentStep / $totalSteps) * 100)
Write-Host ""
Write-Step "Configuring VSCode"
# Install PowerShell extension
$powershellExtensionResult = Install-VSCodeExtension -ExtensionId "ms-vscode.PowerShell" -ExtensionName "PowerShell"
# Install other recommended extensions
$gitLensResult = Install-VSCodeExtension -ExtensionId "eamodio.gitlens" -ExtensionName "GitLens"
$gitGraphResult = Install-VSCodeExtension -ExtensionId "mhutchie.git-graph" -ExtensionName "Git Graph"
# Configure PowerShell 7 integration
$powershellIntegrationResult = Set-VSCodePowerShellIntegration
$results.VSCodeExtensions = $powershellExtensionResult -or $gitLensResult -or $gitGraphResult
}
else {
$results.VSCodeExtensions = $false
}
# Clear progress bar
Write-Progress -Activity "Installing Required Tools" -Completed
@@ -380,6 +490,16 @@ else {
if ($results.VSCode) {
Write-Success "Visual Studio Code"
if ($results.VSCodeExtensions) {
Write-Success " • PowerShell extension"
Write-Success " • GitLens extension"
Write-Success " • Git Graph extension"
Write-Success " • PowerShell 7 terminal integration"
}
else {
Write-Warning " • Some VSCode extensions may need manual installation"
}
}
else {
Write-Error "Visual Studio Code - Installation failed or needs restart"