Skip to content

Commit fc2ea7b

Browse files
committed
Add Install-VSCode.ps1 script
This change adds a new script that can be used to install Visual Studio Code and the PowerShell extension. The intent is for this script to be shipped to the PowerShell Gallery so that one can easily get the script and install VS Code in a single line of PowerShell.
1 parent 2fb82ef commit fc2ea7b

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

scripts/Install-VSCode.ps1

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<#
2+
.SYNOPSIS
3+
Installs Visual Studio Code, the PowerShell extension, and optionally
4+
a list of additional extensions.
5+
6+
.DESCRIPTION
7+
This script can be used to easily install Visual Studio Code and the
8+
PowerShell extension on your machine. You may also specify additional
9+
extensions to be installed using the -AdditionalExtensions parameter.
10+
The -LaunchWhenDone parameter will cause VS Code to be launched as
11+
soon as installation has completed.
12+
13+
Please contribute improvements to this script on GitHub!
14+
15+
https://github.com/PowerShell/vscode-powershell/blob/develop/scripts/Install-VSCode.ps1
16+
17+
.PARAMETER AdditionalExtensions
18+
An array of strings that are the fully-qualified names of extensions to be
19+
installed in addition to the PowerShell extension. The fully qualified
20+
name is formatted as "<publisher name>.<extension name>" and can be found
21+
next to the extension's name in the details tab that appears when you
22+
click an extension in the Extensions panel in Visual Studio Code.
23+
24+
.PARAMETER LaunchWhenDone
25+
When present, causes Visual Studio Code to be launched as soon as installation
26+
has finished.
27+
28+
.EXAMPLE
29+
Install-VSCode.ps1 -LaunchWhenDone
30+
31+
Installs Visual Studio Code and the PowerShell extension and then launches
32+
the editor after installation completes.
33+
34+
.EXAMPLE
35+
Install-VSCode.ps1 -AdditionalExtensions 'eamodio.gitlens', 'vscodevim.vim'
36+
37+
Installs Visual Studio Code, the PowerShell extension, and additional
38+
extensions.
39+
40+
.NOTES
41+
This script is licensed under the MIT License:
42+
43+
Copyright (c) Microsoft Corporation.
44+
45+
Permission is hereby granted, free of charge, to any person obtaining a copy
46+
of this software and associated documentation files (the "Software"), to deal
47+
in the Software without restriction, including without limitation the rights
48+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
49+
copies of the Software, and to permit persons to whom the Software is
50+
furnished to do so, subject to the following conditions:
51+
52+
The above copyright notice and this permission notice shall be included in all
53+
copies or substantial portions of the Software.
54+
55+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
56+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
57+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
58+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
59+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
60+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
61+
SOFTWARE.
62+
#>
63+
[CmdletBinding()]
64+
param(
65+
[Parameter()]
66+
[ValidateNotNull()]
67+
[string[]]$AdditionalExtensions = @(),
68+
69+
[switch]$LaunchWhenDone
70+
)
71+
72+
if (!($IsLinux -or $IsOSX)) {
73+
74+
$codeCmdPath = "C:\Program Files (x86)\Microsoft VS Code\bin\code.cmd"
75+
76+
try {
77+
$ProgressPreference = 'SilentlyContinue'
78+
79+
if (!(Test-Path $codeCmdPath)) {
80+
Write-Host "`nDownloading latest stable Visual Studio Code..." -ForegroundColor Yellow
81+
Remove-Item -Force $env:TEMP\vscode-stable.exe -ErrorAction SilentlyContinue
82+
Invoke-WebRequest -Uri https://vscode-update.azurewebsites.net/latest/win32/stable -OutFile $env:TEMP\vscode-stable.exe
83+
84+
Write-Host "`nInstalling Visual Studio Code..." -ForegroundColor Yellow
85+
Start-Process -Wait $env:TEMP\vscode-stable.exe -ArgumentList /silent, /mergetasks=!runcode
86+
}
87+
else {
88+
Write-Host "`nVisual Studio Code is already installed." -ForegroundColor Yellow
89+
}
90+
91+
$extensions = @("ms-vscode.PowerShell") + $AdditionalExtensions
92+
foreach ($extension in $extensions) {
93+
Write-Host "`nInstalling extension $extension..." -ForegroundColor Yellow
94+
& $codeCmdPath --install-extension $extension
95+
}
96+
97+
if ($LaunchWhenDone) {
98+
Write-Host "`nInstallation complete, starting Visual Studio Code...`n`n" -ForegroundColor Green
99+
& $codeCmdPath
100+
}
101+
else {
102+
Write-Host "`nInstallation complete!`n`n" -ForegroundColor Green
103+
}
104+
}
105+
finally {
106+
$ProgressPreference = 'Continue'
107+
}
108+
}
109+
else {
110+
Write-Error "This script is currently only supported on the Windows operating system."
111+
}

0 commit comments

Comments
 (0)