-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
786c858
commit 211cf75
Showing
5 changed files
with
170 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Write a PowerShell 7 Core script that: | ||
|
||
Checks for Windows Terminal in $env:LOCALAPPDATA "Packages" | ||
|
||
Checks for a settings.json for Windows Terminal in $env:LOCALAPPDATA "Packages" | ||
|
||
Checks for Windows Terminal Preview in $env:LOCALAPPDATA "Packages" | ||
|
||
Checks for a settings.json for Windows Terminal Preview in $env:LOCALAPPDATA "Packages" | ||
|
||
If neither Windows Terminal or Windows Terminal Preview are found, exit with a message that Windows Terminal is not installed. | ||
|
||
If Windows Terminal is detected, but no settings.json for Windows Terminal is found, then run and close wt.exe from $env:ProgramFiles Microsoft.WindowsTerminal | ||
|
||
If Windows Terminal Preview is detected, but no settings.json for Windows Terminal Preview is found, then run and close wt.exe from $env:ProgramFiles Microsoft.WindowsTerminal | ||
|
||
Do not use wildcards to detect files or run wt.exe, parse the directory and use the exact folder name | ||
|
||
Add an additional profile called "WSL System Distro" to Windows Terminal if it exists, that launches the WSL system distro with wsl.exe -u root --system | ||
|
||
Add an additional profile called "WSL System Distro" to Windows Terminal Preview if it exists, that launches the WSL system distro with wsl.exe -u root --system | ||
|
||
Checks if a profile created by the script already exists, and if so, removes the profile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Create a PowerShell 7 Core script that: | ||
|
||
Checks if it is being run as administrator, and, if not, exists with a message that the script must be run as administrator. | ||
|
||
If no argument is specified, the script should display a message that the script must be run with either --reset, --hard-reset, --destructive-reset. | ||
|
||
If the --reset argument is specified, then run wsl.exe --shutdown, wsl.exe --update, and force restart the Windows Subsystem for Linux service in Windows. | ||
|
||
If the --hard-reset argument is specified, then run wsl.exe --shutdown, uninstall Windows Subsystem for Linux, and then run wsl.exe --install. | ||
|
||
If the --descrutive-reset argument is specified, then run wsl.exe --shutdown, run wsl.exe --unregister-all, uninstall Windows Subsystem for Linux, and then run and then run wsl.exe --install. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
$wtPath = Get-ChildItem "$env:LOCALAPPDATA\Packages\" -Directory | Where-Object { $_.Name -like "Microsoft.WindowsTerminal_*" } | Select-Object -ExpandProperty FullName | ||
$wtpPath = Get-ChildItem "$env:LOCALAPPDATA\Packages\" -Directory | Where-Object { $_.Name -like "Microsoft.WindowsTerminalPreview_*" } | Select-Object -ExpandProperty FullName | ||
|
||
if (!$wtPath -and !$wtpPath) { | ||
Write-Host "Windows Terminal is not installed." | ||
exit | ||
} | ||
|
||
$wslProfile = @{ | ||
name = "WSL System Distro" | ||
commandline = "wsl.exe -u root --system" | ||
hidden = $false | ||
guid = [guid]::NewGuid().ToString("B") | ||
icon = "C:\Windows\System32\wsl.exe" | ||
startingDirectory = "" | ||
} | ||
|
||
if ($wtPath) { | ||
Write-Host "Windows Terminal is installed." | ||
if (Test-Path "$wtPath\LocalState\settings.json") { | ||
Write-Host "Windows Terminal settings.json found." | ||
} else { | ||
Write-Host "Windows Terminal settings.json not found, creating..." | ||
$wtExePath = Get-ChildItem "$env:ProgramFiles\WindowsApps\Microsoft.WindowsTerminal_1*" -Directory | Select-Object -ExpandProperty FullName | ||
$mywtProcess = Get-Process -Name "WindowsTerminal" | ||
$mywtPid = $mywtProcess.Id | ||
Start-Process "$wtExePath\wt.exe" | ||
Start-Sleep -Seconds 1 | ||
Get-Process -Name "WindowsTerminal" | Where-Object { $_.Id -ne $mywtPid } | Stop-Process | ||
} | ||
$wtSettings = Get-Content "$wtPath\LocalState\settings.json" -Raw | ConvertFrom-Json | ||
if ($wtSettings.profiles.list | Where-Object { $_.Name -eq $wslProfile.Name }) { | ||
$wtSettings.profiles.list = $wtSettings.profiles.list | Where-Object { $_.Name -ne $wslProfile.Name } | ||
} | ||
$wtSettings.profiles.list += $wslProfile | ||
$wtSettings | ConvertTo-Json -Depth 100 | Set-Content "$wtPath\LocalState\settings.json" | ||
Write-Host "Windows Terminal settings.json updated." | ||
} | ||
|
||
if ($wtpPath) { | ||
Write-Host "Windows Terminal Preview is not installed." | ||
if (Test-Path "$wtpPath\LocalState\settings.json") { | ||
Write-Host "Windows Terminal Preview settings.json found." | ||
} else { | ||
Write-Host "Windows Terminal Preview settings.json not found, creating..." | ||
$wtpExePath = Get-ChildItem "$env:ProgramFiles\WindowsApps\Microsoft.WindowsTerminalPreview_1*" -Directory | Select-Object -ExpandProperty FullName | ||
$mywtProcess = Get-Process -Name "WindowsTerminal" | ||
$mywtPid = $mywtProcess.Id | ||
Start-Process "$wtpExePath\wt.exe" | ||
Start-Sleep -Seconds 1 | ||
Get-Process -Name "WindowsTerminal" | Where-Object { $_.Id -ne $mywtPid } | Stop-Process | ||
} | ||
$wtpSettings = Get-Content "$wtpPath\LocalState\settings.json" -Raw | ConvertFrom-Json | ||
if ($wtpSettings.profiles.list | Where-Object { $_.Name -eq $wslProfile.Name }) { | ||
$wtpSettings.profiles.list = $wtpSettings.profiles.list | Where-Object { $_.Name -ne $wslProfile.Name } | ||
} | ||
$wtpSettings.profiles.list += $wslProfile | ||
$wtpSettings | ConvertTo-Json -Depth 100 | Set-Content "$wtpPath\LocalState\settings.json" | ||
Write-Host "Windows Terminal Preview settings.json updated." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
|
||
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { | ||
Write-Error "This script must be run as an administrator." | ||
Exit 1 | ||
} | ||
|
||
|
||
if (-not $args) { | ||
Write-Error "This script must be run with either --reset, --hard-reset, or --destructive-reset." | ||
Exit 1 | ||
} | ||
|
||
|
||
$arg = $args[0] | ||
switch ($arg) { | ||
"--reset" { | ||
wsl.exe --shutdown -ErrorAction SilentlyContinue 2>$null | ||
Restart-Service "Windows Subsystem for Linux" -Force -ErrorAction SilentlyContinue | ||
if ($LASTEXITCODE -ne 0) { | ||
Restart-Service LxssManager -Force -ErrorAction SilentlyContinue | ||
} | ||
wsl.exe --update > $null | ||
Write-Host "WSL has been shutdown, Windows service restarted, and updated, if applicable." | ||
} | ||
"--hard-reset" { | ||
wsl.exe --shutdown -ErrorAction SilentlyContinue 2>$null | ||
Stop-Service "Windows Subsystem for Linux" -Force -ErrorAction SilentlyContinue | ||
if ($LASTEXITCODE -ne 0) { | ||
Stop-Service LxssManager -Force -ErrorAction SilentlyContinue | ||
} | ||
if (-not (Get-AppxPackage *WindowsSubsystemForLinux* | Remove-AppxPackage -ErrorAction SilentlyContinue 2>$null)) { | ||
Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -ErrorAction SilentlyContinue 2>$null | ||
} | ||
wsl.exe --install --no-launch | ||
Write-Host "WSL has been shutdown and re-installed." | ||
} | ||
"--destructive-reset" { | ||
wsl.exe --shutdown -ErrorAction SilentlyContinue 2>$null | ||
Restart-Service "Windows Subsystem for Linux" -Force -ErrorAction SilentlyContinue | ||
if ($LASTEXITCODE -ne 0) { | ||
Restart-Service LxssManager -Force -ErrorAction SilentlyContinue | ||
} | ||
$distros = Get-ChildItem HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | ForEach-Object { $_.GetValue("DistributionName") } | ||
foreach ($distro in $distros) { | ||
wsl.exe --unregister $distro -ErrorAction SilentlyContinue 2>$null | ||
$folder = Join-Path $env:APPDATA "Microsoft\Windows\Start Menu\Programs\$distro" | ||
if (Test-Path $folder) { | ||
Remove-Item $folder -Recurse -Force | ||
} | ||
} | ||
if (-not (Get-AppxPackage *WindowsSubsystemForLinux* | Remove-AppxPackage -ErrorAction SilentlyContinue 2>$null)) { | ||
Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -ErrorAction SilentlyContinue 2>$null | ||
} | ||
wsl.exe --install --no-launch | ||
Write-Host "WSL has been shutdown, all distros unregistered, and WSL has been re-installed." | ||
} | ||
default { | ||
Write-Error "Invalid argument. This script must be run with either --reset, --hard-reset, or --destructive-reset." | ||
Exit 1 | ||
} | ||
} |