diff --git a/functions/public/Invoke-WPFShortcut.ps1 b/functions/public/Invoke-WPFShortcut.ps1 index 8a26b82a..0c244250 100644 --- a/functions/public/Invoke-WPFShortcut.ps1 +++ b/functions/public/Invoke-WPFShortcut.ps1 @@ -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 }