From 4030154d54e947c44fe1780e77a6d49cc85d29d6 Mon Sep 17 00:00:00 2001 From: "Kim J. Nordmo" Date: Mon, 21 Mar 2022 10:17:57 +0100 Subject: [PATCH] (#8) Expand aliases on core extension package This commit updates all helper scripts to expand the aliases that are currently being used, to instead use the concrete cmdlet instead. --- src/chocolatey-core.extension/CHANGELOG.md | 4 ++++ .../chocolatey-core.extension.nuspec | 2 +- .../extensions/Get-AppInstallLocation.ps1 | 12 ++++++------ .../extensions/Get-AvailableDriveLetter.ps1 | 2 +- .../extensions/Get-EffectiveProxy.ps1 | 10 +++++----- .../extensions/Get-PackageParameters.ps1 | 2 +- .../extensions/Get-UninstallRegistryKey.ps1 | 4 ++-- .../extensions/Remove-Process.ps1 | 10 +++++----- 8 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/chocolatey-core.extension/CHANGELOG.md b/src/chocolatey-core.extension/CHANGELOG.md index 9839389..d0983a4 100644 --- a/src/chocolatey-core.extension/CHANGELOG.md +++ b/src/chocolatey-core.extension/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## 1.3.6 + +- Bugfix: Expand all aliases used in helper scripts ([#8](https://github.com/chocolatey-community/chocolatey-extensions/issues/8)) + ## 1.3.5 - Bugfix `Remove-Process`: Fixed Powershell v2 compatibility issue diff --git a/src/chocolatey-core.extension/chocolatey-core.extension.nuspec b/src/chocolatey-core.extension/chocolatey-core.extension.nuspec index f2a78b7..121ce6e 100644 --- a/src/chocolatey-core.extension/chocolatey-core.extension.nuspec +++ b/src/chocolatey-core.extension/chocolatey-core.extension.nuspec @@ -3,7 +3,7 @@ chocolatey-core.extension - 1.3.5.1 + 1.3.6 Chocolatey Core Extensions Helper functions extending core choco functionality chocolatey diff --git a/src/chocolatey-core.extension/extensions/Get-AppInstallLocation.ps1 b/src/chocolatey-core.extension/extensions/Get-AppInstallLocation.ps1 index ef28520..b5b025a 100644 --- a/src/chocolatey-core.extension/extensions/Get-AppInstallLocation.ps1 +++ b/src/chocolatey-core.extension/extensions/Get-AppInstallLocation.ps1 @@ -1,4 +1,4 @@ -. "$PSScriptRoot\Get-UninstallRegistryKey.ps1" +. "$PSScriptRoot\Get-UninstallRegistryKey.ps1" <# .SYNOPSIS Get application install location @@ -35,7 +35,7 @@ function Get-AppInstallLocation { function strip($path) { if ($path.EndsWith('\')) { return $path -replace '.$' } else { $path } } - function is_dir( $path ) { $path -and (gi $path -ea 0).PsIsContainer -eq $true } + function is_dir( $path ) { $path -and (Get-Item $path -ea 0).PsIsContainer -eq $true } $ErrorActionPreference = "SilentlyContinue" @@ -58,18 +58,18 @@ function Get-AppInstallLocation { } else { Write-Verbose "Found $($key.Count) keys, aborting this method" } $dirs = $Env:ProgramFiles, "$Env:ProgramFiles\*\*" - if (Get-ProcessorBits 64) { $dirs += ${ENV:ProgramFiles(x86)}, "${ENV:ProgramFiles(x86)}\*\*" } + if (Get-OSArchitectureWidth 64) { $dirs += ${ENV:ProgramFiles(x86)}, "${ENV:ProgramFiles(x86)}\*\*" } Write-Verbose "Trying Program Files with 2 levels depth: $dirs" - $location = (ls $dirs | ? {$_.PsIsContainer}) -match $AppNamePattern | select -First 1 | % {$_.FullName} + $location = (Get-ChildItem $dirs | Where-Object {$_.PsIsContainer}) -match $AppNamePattern | Select-Object -First 1 | ForEach-Object {$_.FullName} if (is_dir $location) { return strip $location } Write-Verbose "Trying native commands on PATH" - $location = (Get-Command -CommandType Application) -match $AppNamePattern | select -First 1 | % { Split-Path $_.Source } + $location = (Get-Command -CommandType Application) -match $AppNamePattern | Select-Object -First 1 | ForEach-Object { Split-Path $_.Source } if (is_dir $location) { return strip $location } $appPaths = "\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths" Write-Verbose "Trying Registry: $appPaths" - $location = (ls "HKCU:\$appPaths", "HKLM:\$appPaths") -match $AppNamePattern | select -First 1 + $location = (Get-ChildItem "HKCU:\$appPaths", "HKLM:\$appPaths") -match $AppNamePattern | Select-Object -First 1 if ($location) { $location = Split-Path $location } if (is_dir $location) { return strip $location } diff --git a/src/chocolatey-core.extension/extensions/Get-AvailableDriveLetter.ps1 b/src/chocolatey-core.extension/extensions/Get-AvailableDriveLetter.ps1 index dad71b2..ea29318 100644 --- a/src/chocolatey-core.extension/extensions/Get-AvailableDriveLetter.ps1 +++ b/src/chocolatey-core.extension/extensions/Get-AvailableDriveLetter.ps1 @@ -34,7 +34,7 @@ function Get-AvailableDriveLetter { $i = @() #getting all the used Drive letters reported by the Operating System - $(Get-PSDrive -PSProvider filesystem) | %{$i += $_.name} + $(Get-PSDrive -PSProvider filesystem) | ForEach-Object{$i += $_.name} #Adding the excluded letter $i+=$ExcludedLetters diff --git a/src/chocolatey-core.extension/extensions/Get-EffectiveProxy.ps1 b/src/chocolatey-core.extension/extensions/Get-EffectiveProxy.ps1 index 5356f9d..2600950 100644 --- a/src/chocolatey-core.extension/extensions/Get-EffectiveProxy.ps1 +++ b/src/chocolatey-core.extension/extensions/Get-EffectiveProxy.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS Get the current proxy using several methods @@ -40,16 +40,16 @@ function Get-EffectiveProxy(){ } # Try chocolatey config file - [xml] $cfg = gc $env:ChocolateyInstall\config\chocolatey.config - $p = $cfg.chocolatey.config | % { $_.add } | ? { $_.key -eq 'proxy' } | select -Expand value + [xml] $cfg = Get-Content $env:ChocolateyInstall\config\chocolatey.config + $p = $cfg.chocolatey.config | ForEach-Object { $_.add } | Where-Object { $_.key -eq 'proxy' } | Select-Object -Expand value if ($p) { Write-Verbose "Using choco config proxy" return $p } # Try winhttp proxy - (netsh.exe winhttp show proxy) -match 'Proxy Server\(s\)' | set proxy - $proxy = $proxy -split ' :' | select -Last 1 + (netsh.exe winhttp show proxy) -match 'Proxy Server\(s\)' | Set-Variable proxy + $proxy = $proxy -split ' :' | Select-Object -Last 1 $proxy = $proxy.Trim() if ($proxy) { Write-Verbose "Using winhttp proxy server" diff --git a/src/chocolatey-core.extension/extensions/Get-PackageParameters.ps1 b/src/chocolatey-core.extension/extensions/Get-PackageParameters.ps1 index 5b77ff0..2b5f6a5 100644 --- a/src/chocolatey-core.extension/extensions/Get-PackageParameters.ps1 +++ b/src/chocolatey-core.extension/extensions/Get-PackageParameters.ps1 @@ -22,7 +22,7 @@ function Get-PackageParameters { $res = @{} $re = "\/([a-zA-Z0-9]+)(:[`"'].+?[`"']|[^ ]+)?" - $results = $Parameters | Select-String $re -AllMatches | select -Expand Matches + $results = $Parameters | Select-String $re -AllMatches | Select-Object -Expand Matches foreach ($m in $results) { if (!$m) { continue } # must because of posh 2.0 bug: https://github.com/chocolatey/chocolatey-coreteampackages/issues/465 diff --git a/src/chocolatey-core.extension/extensions/Get-UninstallRegistryKey.ps1 b/src/chocolatey-core.extension/extensions/Get-UninstallRegistryKey.ps1 index 6431f44..062868e 100644 --- a/src/chocolatey-core.extension/extensions/Get-UninstallRegistryKey.ps1 +++ b/src/chocolatey-core.extension/extensions/Get-UninstallRegistryKey.ps1 @@ -81,13 +81,13 @@ function Get-UninstallRegistryKey { $keyPaths = $keys | Select-Object -ExpandProperty PSPath try { - [array]$foundKey = Get-ItemProperty -Path $keyPaths -ea 0 | ? { $_.DisplayName -like $SoftwareName } + [array]$foundKey = Get-ItemProperty -Path $keyPaths -ea 0 | Where-Object { $_.DisplayName -like $SoftwareName } $success = $true } catch { Write-Debug "Found bad key." foreach ($key in $keys){ try{ Get-ItemProperty $key.PsPath > $null } catch { $badKey = $key.PsPath }} Write-Verbose "Skipping bad key: $badKey" - [array]$keys = $keys | ? { $badKey -NotContains $_.PsPath } + [array]$keys = $keys | Where-Object { $badKey -NotContains $_.PsPath } } if ($success) { break; } diff --git a/src/chocolatey-core.extension/extensions/Remove-Process.ps1 b/src/chocolatey-core.extension/extensions/Remove-Process.ps1 index 857e0c3..c0e2bc5 100644 --- a/src/chocolatey-core.extension/extensions/Remove-Process.ps1 +++ b/src/chocolatey-core.extension/extensions/Remove-Process.ps1 @@ -1,4 +1,4 @@ -<# +<# .SYNOPSIS Ensure that process is stopped in reliable way @@ -71,7 +71,7 @@ function Remove-Process { # Process might spawn multiple children, typical for browsers; remove all children as parent will handle them if (!$WithChildren) { Write-Verbose "Remove all children processes" - $proc = $proc | ? { $proc.Id -notcontains $_.ParentId } + $proc = $proc | Where-Object { $proc.Id -notcontains $_.ParentId } } foreach ($p in $proc) { @@ -81,20 +81,20 @@ function Remove-Process { # wait for app to shut down for some time, max 5s for ($i=0; $i -lt 5; $i++) { Start-Sleep 1 - $p2 = ps -PID $p.id -ea 0 + $p2 = Get-Process -PID $p.id -ea 0 if (!$p2) { break } } } # Return value of CloseMainWindow() 'True' is not reliable # so if process is still active kill it - $p2 = ps -PID $p.id -ea 0 + $p2 = Get-Process -PID $p.id -ea 0 if (($p.Process.Name -eq $p2.Name) -and ($p.Process.StartTime -eq $p2.StartTime)) { $p | Stop-Process -ea STOP Start-Sleep 1 # Running to fast here still gets the killed process in next line } - $p2 = ps -PID $p.id -ea 0 + $p2 = Get-Process -PID $p.id -ea 0 if (($p.Process.Name -eq $p2.Name) -and ($p.Process.StartTime -eq $p2.StartTime)) { Write-Warning "Process '$($p.Name)' run by user '$($p.Username)' can't be closed" }