From 9dca986b74909a9f78e6bec1a74fba89b3ba4340 Mon Sep 17 00:00:00 2001 From: lksz Date: Tue, 19 Jan 2021 10:17:23 -0500 Subject: [PATCH] Profile update/fixes Fixed Get-PowerShellPath - was failing when a zombie process was alive Fixed Remove-Item failing when setting up profile. --- Setup-Profile.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Setup-Profile.ps1 b/Setup-Profile.ps1 index 8acf000..4c1a869 100644 --- a/Setup-Profile.ps1 +++ b/Setup-Profile.ps1 @@ -174,7 +174,7 @@ Get-Command Reload-MyScripts -ErrorAction SilentlyContinue | ForEach-Object { . $local:errMsg = $(Invoke-ExpressionEx -sudo:$shouldSudo @" if( -not (Test-Path $(Split-Path -Parent $p)) ) { New-Item -Type Directory $(Split-Path -Parent $p) -Force }; Copy-Item $($tmpOutput.FullName) $p -Force:`$$Force -ErrorAction Stop | Out-Null; - Remove-Item $($tmpOutput.FullName) -Force:`$$Force -ErrorAction Stop + Remove-Item $($tmpOutput.FullName) -Force:`$$Force -ErrorAction SilentlyContinue "@ 2>&1) if ( $errMsg ) { Write-Error "$errMsg" @@ -223,7 +223,7 @@ Get-Command Reload-MyScripts -ErrorAction SilentlyContinue | ForEach-Object { . ####################################################################### function ProfileCode_common { function Get-PowerShellPath { - Get-Process -PID $PID | ForEach-Object { $_.Path, $_.Parent.Path } | Where-Object { $_ -match 'powershell|pwsh' } | Select-Object -First 1 + Get-Process -PID $PID | ForEach-Object { $_.Path, $_.Parent.Path } | Where-Object { $_ -match $('(powershell|pwsh)' + "`$") } | Select-Object -First 1 } function ConvertTo-Base64 { @@ -254,10 +254,10 @@ function Invoke-ExpressionEx { $local:sudo_exec = [string]::Empty if ( (Get-Command scoop -ErrorAction SilentlyContinue) ) { $sudo_exec = $(scoop which gsudo *>&1) - if ( $sudo_exec -match 'not found' ) { + if ( "$sudo_exec" -match 'not found' ) { $sudo_exec = $(scoop which sudo *>&1) } - if ( $sudo_exec -match 'not found' ) { $sudo_exec = [string]::Empty } + if ( "$sudo_exec" -match 'not found' ) { $sudo_exec = [string]::Empty } } if ( $sudo_exec ) { & $sudo_exec $sudo_cmd