mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2024-12-22 05:51:30 -06:00
Optimized: Shortcut Creation and PS7 Tweak (#2314)
* Clarified the wording * Handle Computers without Windows Terminal (eg Win10) * Modify Shortcut creation to use PS7 if possible
This commit is contained in:
parent
e5ba389606
commit
d4faee5fbc
@ -2305,8 +2305,8 @@
|
||||
]
|
||||
},
|
||||
"WPFTweaksPowershell7": {
|
||||
"Content": "Replace Default Powershell 5 to Powershell 7",
|
||||
"Description": "This will edit the config file of the Windows Terminal Replacing the Powershell 5 to Powershell 7 and install Powershell 7 if necessary",
|
||||
"Content": "Change Windows Terminal default: PowerShell 5 -> PowerShell 7",
|
||||
"Description": "This will edit the config file of the Windows Terminal replacing PowerShell 5 with PowerShell 7 and installing PS7 if necessary",
|
||||
"category": "Essential Tweaks",
|
||||
"panel": "1",
|
||||
"Order": "a009_",
|
||||
|
@ -17,14 +17,20 @@ function Invoke-WPFShortcut {
|
||||
[bool]$RunAsAdmin = $false
|
||||
)
|
||||
|
||||
# Preper the Shortcut Fields and add an a Custom Icon if it's available at "$env:TEMP\cttlogo.png", else don't add a Custom Icon.
|
||||
# add an a Custom Icon if it's available at "$env:TEMP\cttlogo.png", else don't add a Custom Icon.
|
||||
$iconPath = $null
|
||||
Switch ($ShortcutToAdd) {
|
||||
"WinUtil" {
|
||||
$SourceExe = "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe"
|
||||
$IRM = 'irm https://christitus.com/win | iex'
|
||||
$Powershell = '-ExecutionPolicy Bypass -Command "Start-Process powershell.exe -verb runas -ArgumentList'
|
||||
$ArgumentsToSourceExe = "$powershell '$IRM'"
|
||||
# Use Powershell 7 if installed and fallback to PS5 if not
|
||||
if (Get-Command "pwsh" -ErrorAction SilentlyContinue){
|
||||
$shell = "pwsh.exe"
|
||||
}
|
||||
else{
|
||||
$shell = "powershell.exe"
|
||||
}
|
||||
|
||||
$shellArgs = "-ExecutionPolicy Bypass -Command `"Start-Process $shell -verb runas -ArgumentList `'-Command `"irm https://christitus.com/win | iex`"`'"
|
||||
|
||||
$DestinationName = "WinUtil.lnk"
|
||||
|
||||
Invoke-WebRequest -Uri "https://christitus.com/images/logo-full.png" -OutFile "$env:TEMP\cttlogo.png"
|
||||
@ -52,9 +58,9 @@ function Invoke-WPFShortcut {
|
||||
# Prepare the Shortcut paramter
|
||||
$WshShell = New-Object -comObject WScript.Shell
|
||||
$Shortcut = $WshShell.CreateShortcut($FileBrowser.FileName)
|
||||
$Shortcut.TargetPath = $SourceExe
|
||||
$Shortcut.Arguments = $ArgumentsToSourceExe
|
||||
if ($iconPath -ne $null) {
|
||||
$Shortcut.TargetPath = $shell
|
||||
$Shortcut.Arguments = $shellArgs
|
||||
if ($null -ne $iconPath) {
|
||||
$shortcut.IconLocation = $iconPath
|
||||
}
|
||||
|
||||
|
@ -25,22 +25,29 @@ function Invoke-WPFTweakPS7{
|
||||
$targetTerminalName = "Windows PowerShell"
|
||||
}
|
||||
}
|
||||
|
||||
$settingsPath = "$env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json"
|
||||
if (Test-Path -Path $settingsPath) {
|
||||
Write-Host "Settings file found."
|
||||
$settingsContent = Get-Content -Path $settingsPath | ConvertFrom-Json
|
||||
$ps7Profile = $settingsContent.profiles.list | Where-Object { $_.name -eq $targetTerminalName }
|
||||
if ($ps7Profile) {
|
||||
$settingsContent.defaultProfile = $ps7Profile.guid
|
||||
$updatedSettings = $settingsContent | ConvertTo-Json -Depth 100
|
||||
Set-Content -Path $settingsPath -Value $updatedSettings
|
||||
Write-Host "Default profile updated to $targetTerminalName using the name attribute."
|
||||
} else {
|
||||
Write-Host "No PowerShell 7 profile found in Windows Terminal settings using the name attribute."
|
||||
}
|
||||
} else {
|
||||
Write-Host "Settings file not found at $settingsPath"
|
||||
# Check if the Windows Terminal is installed and return if not (Prerequisite for the following code)
|
||||
if (-not (Get-Command "wt" -ErrorAction SilentlyContinue)){
|
||||
Write-Host "Windows Terminal not installed. Skipping Terminal preference"
|
||||
return
|
||||
}
|
||||
# Check if the Windows Terminal settings.json file exists and return if not (Prereqisite for the following code)
|
||||
$settingsPath = "$env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json"
|
||||
if (-not (Test-Path -Path $settingsPath)){
|
||||
Write-Host "Windows Terminal Settings file not found at $settingsPath"
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "Settings file found."
|
||||
$settingsContent = Get-Content -Path $settingsPath | ConvertFrom-Json
|
||||
$ps7Profile = $settingsContent.profiles.list | Where-Object { $_.name -eq $targetTerminalName }
|
||||
if ($ps7Profile) {
|
||||
$settingsContent.defaultProfile = $ps7Profile.guid
|
||||
$updatedSettings = $settingsContent | ConvertTo-Json -Depth 100
|
||||
Set-Content -Path $settingsPath -Value $updatedSettings
|
||||
Write-Host "Default profile updated to " -NoNewline
|
||||
Write-Host "$targetTerminalName " -ForegroundColor White -NoNewline
|
||||
Write-Host "using the name attribute."
|
||||
} else {
|
||||
Write-Host "No PowerShell 7 profile found in Windows Terminal settings using the name attribute."
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user