-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall-powerShellCore.ps1
More file actions
40 lines (34 loc) · 1.42 KB
/
Copy pathinstall-powerShellCore.ps1
File metadata and controls
40 lines (34 loc) · 1.42 KB
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
#!/usr/bin/env powershell.exe
#Requires -Version 5
#Requires -RunAsAdministrator
#Requires -PSEdition Desktop
param (
[switch] $Force = $false
)
Set-StrictMode -Version 2.0
$wingetCmd = (Get-Command -Name winget.exe -ErrorAction SilentlyContinue)
if ($wingetCmd) {
$wingetExe = "$($wingetCmd.Source)"
}
else {
$wingetExe = Join-Path -Path "$env:LOCALAPPDATA" -ChildPath "Microsoft\WindowsApps\winget.exe"
}
if (-not (Test-Path -Path "$wingetExe")) {
throw "Unable to locate WinGet, it must be installed first before this script will function."
}
### Check for and install Powershell Core if necessary
Write-Host "Checking for PowerShell Core..." -ForegroundColor "Green"
$powerShellPath = "C:\Program Files\PowerShell\7\pwsh.exe"
if (-not (Test-Path -Path $powerShellPath) -or $Force) {
Write-Host "PowerShell Core missing, preparing for install using WinGet."
Write-Host ""
& "$wingetExe" install Microsoft.PowerShell --silent --accept-package-agreements --accept-source-agreements --override "/quiet /passive ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 ADD_FILE_CONTEXT_MENU_RUNPOWERSHELL=1 ENABLE_PSREMOTING=1 REGISTER_MANIFEST=1"
if (Test-Path -Path ".\configure-executionPolicies.ps1") {
& ".\configure-executionPolicies.ps1"
}
Write-Host "PowerShell Core installed." -ForegroundColor "Cyan"
}
else {
Write-Host "PowerShell Core already installed." -ForegroundColor "Cyan"
}
Write-Host ""