@@ -111,6 +111,45 @@ catch {
111
111
exit 1
112
112
}
113
113
114
+ # =================================
115
+ # Obtain the latest pwsh binary and other pwsh information
116
+ # =================================
117
+ #
118
+ # This will install pwsh on the machine, because it's not installed by default.
119
+ # It contains a bunch of new features compared to "powershell" and is sometimes more stable as well.
120
+ #
121
+ # url for Github API to get the latest release of pwsh
122
+ #
123
+ # TODO update this to /releases/latest once 7.5.0 is out, as it adds support for arm64 MSIs
124
+ [string ]$PwshUrl = " https://api.github.com/repos/PowerShell/PowerShell/releases/tags/v7.5.0-preview.2"
125
+
126
+ # Name of the MSI file that should be verified and downloaded
127
+ [string ]$PwshMsiName = " PowerShell-.*-win-arm64.msi"
128
+
129
+ try {
130
+ [System.Object ]$PwshRestData = Invoke-RestMethod - Uri $PwshUrl - Method Get - Headers $GithubHeaders - TimeoutSec 10 | Select-Object - Property assets, body
131
+ [System.Object ]$PwshAsset = $PwshRestData.assets | Where-Object { $_.name -match $PwshMsiName }
132
+ if ($PwshRestData.body -match " \b$ ( [Regex ]::Escape($PwshAsset.name )) \r\n.*?([a-zA-Z0-9]{64})" -eq $True ) {
133
+ [System.Object ]$GitHubPwsh = [PSCustomObject ]@ {
134
+ DownloadUrl = [string ]$PwshAsset.browser_download_url
135
+ Hash = [string ]$Matches [1 ].ToUpper()
136
+ OutFile = " ./pwsh-installer.msi"
137
+ }
138
+ }
139
+ else {
140
+ Write-Error " Could not find hash for $PwshMsiName "
141
+ exit 1
142
+ }
143
+ }
144
+ catch {
145
+ Write-Error @"
146
+ "Message: "$ ( $_.Exception.Message ) `n
147
+ "Error Line: "$ ( $_.InvocationInfo.Line ) `n
148
+ "Line Number: "$ ( $_.InvocationInfo.ScriptLineNumber ) `n
149
+ "@
150
+ exit 1
151
+ }
152
+
114
153
# ======================
115
154
# WINDOWS DEVELOPER MODE
116
155
# ======================
@@ -173,6 +212,38 @@ Start-Process -Wait $GitHubGit.OutFile '/VERYSILENT /NORESTART /NOCANCEL /SP- /C
173
212
174
213
Write-Output " Finished installing Git for Windows."
175
214
215
+ # ======================
216
+ # PWSH (PowerShell)
217
+ # ======================
218
+
219
+ Write-Output " Downloading pwsh..."
220
+
221
+ $ProgressPreference = ' SilentlyContinue'
222
+ Invoke-WebRequest - UseBasicParsing - Uri $GitHubPwsh.DownloadUrl - OutFile $GitHubPwsh.OutFile
223
+ $ProgressPreference = ' Continue'
224
+
225
+ if ((Get-FileHash - Path $GitHubPwsh.OutFile - Algorithm SHA256).Hash.ToUpper() -ne $GitHubPwsh.Hash ) {
226
+ Write-Error " Computed checksum for $ ( $GitHubPwsh.OutFile ) did not match $ ( $GitHubPwsh.Hash ) "
227
+ exit 1
228
+ }
229
+
230
+ Write-Output " Installing pwsh..."
231
+
232
+ # Get the full path to the MSI in the current working directory
233
+ $MsiPath = Resolve-Path $GitHubPwsh.OutFile
234
+
235
+ # Define arguments for silent installation
236
+ $MsiArguments = " /qn /i `" $MsiPath `" ADD_PATH=1"
237
+
238
+ # Install pwsh using msiexec
239
+ Start-Process msiexec.exe - Wait - ArgumentList $MsiArguments
240
+
241
+ # TODO remove once 7.5.0 is out
242
+ Write-Output " Copying pwsh-preview.cmd to pwsh.cmd as a temporary measure until 7.5.0 is out..."
243
+ Copy-Item " C:\Program Files\PowerShell\7-preview\preview\pwsh-preview.cmd" " C:\Program Files\PowerShell\7-preview\preview\pwsh.cmd"
244
+
245
+ Write-Output " Finished installing pwsh."
246
+
176
247
# ======================
177
248
# GITHUB ACTIONS RUNNER
178
249
# ======================
0 commit comments