-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Update-Choco.ps1
82 lines (68 loc) · 2.05 KB
/
Update-Choco.ps1
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<#
.SYNOPSIS
Upgrades all outdated chocolatey packages.
.PARAMETER all
Same as -yes
.PARAMETER yes
Adds the -yes parameter, accepting all updates without prompting
#>
param(
[switch] $Yes,
[switch] $All,
[string] $WinTermPID
)
Begin
{
$script:mswinterm = 'microsoft-windows-terminal'
function CheckTerminalUpgrade
{
Write-Host "`n... running from Windows Terminal; please wait while checking status of $mswinterm" -ForegroundColor Cyan
$available = choco outdated | where { $_ -match $mswinterm }
if ($available)
{
Write-Host '... upgrade is available; this window will close' -ForegroundColor Cyan
$ans = Read-Host '... Upgrade now? (Y/N) [Y]'
if ($ans -eq '' -or $ans -eq 'Y')
{
Start-Process -Verb RunAs `
-FilePath "$env:ComSpec" `
-ArgumentList '/c', 'start', "powershell.exe -f `"$PSCommandPath`" -WinTermPID $PID"
}
}
else {
Write-Host '... Windows Terminal is up to date'
}
}
function UpgradeWindowsTerminal
{
Write-Host '... upgrading Microsoft Windows Terminal'
# stop the PowerShell process running within the calling Terminal window
# Note this only stops the process from the calling window, not other Terminal windows
Stop-Process $WinTermPID -Force
# stop all Terminal windows!
Stop-Process -Name 'WindowsTerminal' -Force
choco upgrade -y $mswinterm
Read-Host "... done, press Enter to close this window"
}
}
Process
{
if ($WinTermPID)
{
UpgradeWindowsTerminal
return
}
# note that choco pin command doesn't seem to work as advertised!
$yesarg = ''
if ($Yes -or $All) { $yesarg = '-y' }
#choco upgrade $yesarg all --except="'linqpad,linqpad5,linqpad5.install'"
if ($env:WT_SESSION)
{
choco upgrade $yesarg all --except="'$mswinterm'"
CheckTerminalUpgrade
}
else
{
choco upgrade $yesarg all
}
}