-
-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathUpdate-PowerShell.ps1
More file actions
49 lines (40 loc) · 814 Bytes
/
Copy pathUpdate-PowerShell.ps1
File metadata and controls
49 lines (40 loc) · 814 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<#
.SYNOPSIS
Update PowerShell to the latest version using winget.
.PARAMETER Silent
Suppresses output from winget.
#>
[CmdletBinding(SupportsShouldProcess = $true)]
param (
[switch] $Silent
)
Begin
{
function UpdatePS
{
# must use an array of arguments rather than splatting a hashtable
# so we can pass double-dash arguments to winget
$plist = @(
'--id', 'Microsoft.PowerShell',
'--source', 'winget',
'--accept-package-agreements', '',
'--accept-source-agreements', ''
)
if ($Silent) { $plist += '--silent', '' }
winget upgrade @plist
return $LASTEXITCODE
}
}
Process
{
Write-Host "Update PowerShell`n" -fo Blue
$code = UpdatePS
if ($code -eq 0)
{
Write-Host "`n... Done. Open a new console" -fo Green
}
else
{
Write-Host 'PowerShell is up to date'
}
}