5
5
Install PowerShell on Windows, Linux or macOS.
6
6
. DESCRIPTION
7
7
By default, the latest PowerShell release package will be installed.
8
- If '-Daily ' is specified, then the latest PowerShell daily package will be installed.
8
+ If '-Preview ' is specified, then the latest PowerShell preview package will be installed.
9
9
. Parameter Destination
10
10
The destination path to install PowerShell to.
11
- . Parameter Daily
12
- Install PowerShell from the daily build.
13
- Note that the 'PackageManagement' module is required to install a daily package.
11
+ . Parameter Preview
12
+ Install the latest PowerShell preview build.
14
13
. Parameter DoNotOverwrite
15
14
Do not overwrite the destination folder if it already exists.
16
15
. Parameter AddToPath
17
16
On Windows, add the absolute destination path to the 'User' scope environment variable 'Path';
18
17
On Linux, make the symlink '/usr/bin/pwsh' points to "$Destination/pwsh";
19
18
On MacOS, make the symlink '/usr/local/bin/pwsh' points to "$Destination/pwsh".
20
19
. EXAMPLE
21
- Install the daily build
22
- .\install-powershell.ps1 -Daily
20
+ Install the preview build
21
+ .\install-powershell.ps1 -Preview
23
22
. EXAMPLE
24
23
Invoke this script directly from GitHub
25
- Invoke-Expression "& { $(Invoke-RestMethod 'https://aka.ms/install-powershell.ps1') } -daily "
24
+ Invoke-Expression "& { $(Invoke-RestMethod 'https://aka.ms/install-powershell.ps1') } -Preview "
26
25
#>
27
- [CmdletBinding (DefaultParameterSetName = " Daily " )]
26
+ [CmdletBinding ()]
28
27
param (
29
- [Parameter (ParameterSetName = " Daily" )]
30
- [string ] $Destination ,
28
+ [Parameter ()]
29
+ [switch ] $Preview ,
30
+
31
+ [Parameter ()]
32
+ [switch ] $Daily , # Exists for backward compatibility
31
33
32
- [Parameter (ParameterSetName = " Daily " )]
33
- [switch ] $Daily ,
34
+ [Parameter ()]
35
+ [string ] $Destination ,
34
36
35
- [Parameter (ParameterSetName = " Daily " )]
37
+ [Parameter ()]
36
38
[switch ] $DoNotOverwrite ,
37
39
38
- [Parameter (ParameterSetName = " Daily " )]
40
+ [Parameter ()]
39
41
[switch ] $AddToPath ,
40
42
41
43
[Parameter (ParameterSetName = " MSI" )]
@@ -48,10 +50,7 @@ param(
48
50
[switch ] $AddExplorerContextMenu ,
49
51
50
52
[Parameter (ParameterSetName = " MSI" )]
51
- [switch ] $EnablePSRemoting ,
52
-
53
- [Parameter ()]
54
- [switch ] $Preview
53
+ [switch ] $EnablePSRemoting
55
54
)
56
55
57
56
Set-StrictMode - Version 3.0
@@ -61,15 +60,20 @@ $IsLinuxEnv = (Get-Variable -Name "IsLinux" -ErrorAction Ignore) -and $IsLinux
61
60
$IsMacOSEnv = (Get-Variable - Name " IsMacOS" - ErrorAction Ignore) -and $IsMacOS
62
61
$IsWinEnv = ! $IsLinuxEnv -and ! $IsMacOSEnv
63
62
63
+ if ($Daily ) {
64
+ $Preview = $true
65
+ Write-Warning " The '-Daily' build is deprecated. Continuing as if '-Preview' was specified instead."
66
+ }
67
+
64
68
if (-not $Destination ) {
65
69
if ($IsWinEnv ) {
66
70
$Destination = " $env: LOCALAPPDATA \Microsoft\powershell"
67
71
} else {
68
72
$Destination = " ~/.powershell"
69
73
}
70
74
71
- if ($Daily ) {
72
- $Destination = " ${Destination} -daily "
75
+ if ($Preview ) {
76
+ $Destination = " ${Destination} -preview "
73
77
}
74
78
}
75
79
@@ -265,145 +269,68 @@ try {
265
269
$originalValue = [Net.ServicePointManager ]::SecurityProtocol
266
270
[Net.ServicePointManager ]::SecurityProtocol = [Net.ServicePointManager ]::SecurityProtocol -bor [Net.SecurityProtocolType ]::Tls12
267
271
268
- if ($Daily ) {
269
- $metadata = Invoke-RestMethod ' https://aka.ms/pwsh-buildinfo-daily'
272
+ $metadata = Invoke-RestMethod ' https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/metadata.json'
273
+ if ($Preview ) {
274
+ $release = $metadata.PreviewReleaseTag -replace ' ^v'
275
+ } else {
270
276
$release = $metadata.ReleaseTag -replace ' ^v'
277
+ }
271
278
272
- # Get version from currently installed PowerShell Daily if available.
273
- $pwshPath = if ($IsWinEnv ) {Join-Path $Destination " pwsh.exe" } else {Join-Path $Destination " pwsh" }
274
- $currentlyInstalledVersion = if (Test-Path $pwshPath ) {
275
- ((& $pwshPath - version) -split " " )[1 ]
276
- }
277
-
278
- if ($currentlyInstalledVersion -eq $release ) {
279
- Write-Verbose " Latest PowerShell Daily already installed." - Verbose
280
- return
281
- }
282
-
283
- if ($IsWinEnv ) {
284
- if ($UseMSI ) {
285
- $packageName = " PowerShell-${release} -win-${architecture} .msi"
286
- } else {
287
- $packageName = " PowerShell-${release} -win-${architecture} .zip"
288
- }
289
- } elseif ($IsLinuxEnv ) {
290
- $packageName = " powershell-${release} -linux-${architecture} .tar.gz"
291
- } elseif ($IsMacOSEnv ) {
292
- $packageName = " powershell-${release} -osx-${architecture} .tar.gz"
279
+ if ($IsWinEnv ) {
280
+ if ($UseMSI ) {
281
+ $packageName = " PowerShell-${release} -win-${architecture} .msi"
282
+ } else {
283
+ $packageName = " PowerShell-${release} -win-${architecture} .zip"
293
284
}
285
+ } elseif ($IsLinuxEnv ) {
286
+ $packageName = " powershell-${release} -linux-${architecture} .tar.gz"
287
+ } elseif ($IsMacOSEnv ) {
288
+ $packageName = " powershell-${release} -osx-${architecture} .tar.gz"
289
+ }
294
290
295
- if ($architecture -ne " x64" ) {
296
- throw " The OS architecture is '$architecture '. However, we currently only support daily package for x64."
297
- }
291
+ $downloadURL = " https://github.com/PowerShell/PowerShell/releases/download/v${release} /${packageName} "
292
+ Write-Verbose " About to download package from '$downloadURL '" - Verbose
298
293
299
- $downloadURL = " https://powershellinfraartifacts-gkhedzdeaghdezhr.z01.azurefd.net/install/$ ( $metadata.ReleaseTag ) /$packageName "
300
- Write-Verbose " About to download package from '$downloadURL '" - Verbose
294
+ $packagePath = Join-Path - Path $tempDir - ChildPath $packageName
295
+ if (! $PSVersionTable.ContainsKey (' PSEdition' ) -or $PSVersionTable.PSEdition -eq " Desktop" ) {
296
+ # On Windows PowerShell, progress can make the download significantly slower
297
+ $oldProgressPreference = $ProgressPreference
298
+ $ProgressPreference = " SilentlyContinue"
299
+ }
301
300
302
- $packagePath = Join-Path - Path $tempDir - ChildPath $packageName
301
+ try {
302
+ Invoke-WebRequest - Uri $downloadURL - OutFile $packagePath
303
+ } finally {
303
304
if (! $PSVersionTable.ContainsKey (' PSEdition' ) -or $PSVersionTable.PSEdition -eq " Desktop" ) {
304
- # On Windows PowerShell, progress can make the download significantly slower
305
- $oldProgressPreference = $ProgressPreference
306
- $ProgressPreference = " SilentlyContinue"
305
+ $ProgressPreference = $oldProgressPreference
307
306
}
307
+ }
308
308
309
- try {
310
- Invoke-WebRequest - Uri $downloadURL - OutFile $packagePath
311
- } finally {
312
- if (! $PSVersionTable.ContainsKey (' PSEdition' ) -or $PSVersionTable.PSEdition -eq " Desktop" ) {
313
- $ProgressPreference = $oldProgressPreference
314
- }
315
- }
316
-
317
- $contentPath = Join-Path - Path $tempDir - ChildPath " new"
318
-
319
- $null = New-Item - ItemType Directory - Path $contentPath - ErrorAction SilentlyContinue
320
- if ($IsWinEnv ) {
321
- if ($UseMSI -and $Quiet ) {
322
- Write-Verbose " Performing quiet install"
323
- $ArgumentList = @ (" /i" , $packagePath , " /quiet" )
324
- if ($MSIArguments ) {
325
- $ArgumentList += $MSIArguments
326
- }
327
- $process = Start-Process msiexec - ArgumentList $ArgumentList - Wait - PassThru
328
- if ($process.exitcode -ne 0 ) {
329
- throw " Quiet install failed, please rerun install without -Quiet switch or ensure you have administrator rights"
330
- }
331
- } elseif ($UseMSI ) {
332
- if ($MSIArguments ) {
333
- Start-Process $packagePath - ArgumentList $MSIArguments - Wait
334
- } else {
335
- Start-Process $packagePath - Wait
336
- }
337
- } else {
338
- Expand-ArchiveInternal - Path $packagePath - DestinationPath $contentPath
339
- }
340
- } else {
341
- tar zxf $packagePath - C $contentPath
342
- }
343
- } else {
344
- $metadata = Invoke-RestMethod https:// raw.githubusercontent.com / PowerShell/ PowerShell/ master/ tools/ metadata.json
345
- if ($Preview ) {
346
- $release = $metadata.PreviewReleaseTag -replace ' ^v'
347
- } else {
348
- $release = $metadata.ReleaseTag -replace ' ^v'
349
- }
309
+ $contentPath = Join-Path - Path $tempDir - ChildPath " new"
350
310
351
- if ($IsWinEnv ) {
352
- if ($UseMSI ) {
353
- $packageName = " PowerShell-${release} -win-${architecture} .msi"
354
- } else {
355
- $packageName = " PowerShell-${release} -win-${architecture} .zip"
311
+ $null = New-Item - ItemType Directory - Path $contentPath - ErrorAction SilentlyContinue
312
+ if ($IsWinEnv ) {
313
+ if ($UseMSI -and $Quiet ) {
314
+ Write-Verbose " Performing quiet install"
315
+ $ArgumentList = @ (" /i" , $packagePath , " /quiet" )
316
+ if ($MSIArguments ) {
317
+ $ArgumentList += $MSIArguments
356
318
}
357
- } elseif ($IsLinuxEnv ) {
358
- $packageName = " powershell-${release} -linux-${architecture} .tar.gz"
359
- } elseif ($IsMacOSEnv ) {
360
- $packageName = " powershell-${release} -osx-${architecture} .tar.gz"
361
- }
362
-
363
- $downloadURL = " https://github.com/PowerShell/PowerShell/releases/download/v${release} /${packageName} "
364
- Write-Verbose " About to download package from '$downloadURL '" - Verbose
365
-
366
- $packagePath = Join-Path - Path $tempDir - ChildPath $packageName
367
- if (! $PSVersionTable.ContainsKey (' PSEdition' ) -or $PSVersionTable.PSEdition -eq " Desktop" ) {
368
- # On Windows PowerShell, progress can make the download significantly slower
369
- $oldProgressPreference = $ProgressPreference
370
- $ProgressPreference = " SilentlyContinue"
371
- }
372
-
373
- try {
374
- Invoke-WebRequest - Uri $downloadURL - OutFile $packagePath
375
- } finally {
376
- if (! $PSVersionTable.ContainsKey (' PSEdition' ) -or $PSVersionTable.PSEdition -eq " Desktop" ) {
377
- $ProgressPreference = $oldProgressPreference
319
+ $process = Start-Process msiexec - ArgumentList $ArgumentList - Wait - PassThru
320
+ if ($process.exitcode -ne 0 ) {
321
+ throw " Quiet install failed, please rerun install without -Quiet switch or ensure you have administrator rights"
378
322
}
379
- }
380
-
381
- $contentPath = Join-Path - Path $tempDir - ChildPath " new"
382
-
383
- $null = New-Item - ItemType Directory - Path $contentPath - ErrorAction SilentlyContinue
384
- if ($IsWinEnv ) {
385
- if ($UseMSI -and $Quiet ) {
386
- Write-Verbose " Performing quiet install"
387
- $ArgumentList = @ (" /i" , $packagePath , " /quiet" )
388
- if ($MSIArguments ) {
389
- $ArgumentList += $MSIArguments
390
- }
391
- $process = Start-Process msiexec - ArgumentList $ArgumentList - Wait - PassThru
392
- if ($process.exitcode -ne 0 ) {
393
- throw " Quiet install failed, please rerun install without -Quiet switch or ensure you have administrator rights"
394
- }
395
- } elseif ($UseMSI ) {
396
- if ($MSIArguments ) {
397
- Start-Process $packagePath - ArgumentList $MSIArguments - Wait
398
- } else {
399
- Start-Process $packagePath - Wait
400
- }
323
+ } elseif ($UseMSI ) {
324
+ if ($MSIArguments ) {
325
+ Start-Process $packagePath - ArgumentList $MSIArguments - Wait
401
326
} else {
402
- Expand-ArchiveInternal - Path $packagePath - DestinationPath $contentPath
327
+ Start-Process $packagePath - Wait
403
328
}
404
329
} else {
405
- tar zxf $packagePath - C $contentPath
330
+ Expand-ArchiveInternal - Path $packagePath - DestinationPath $contentPath
406
331
}
332
+ } else {
333
+ tar zxf $packagePath - C $contentPath
407
334
}
408
335
409
336
if (-not $UseMSI ) {
0 commit comments