From ab384029f1fcf97dbe93157e21e88e0a03ffb5e5 Mon Sep 17 00:00:00 2001 From: Martin Wiethan <47688561+Marterich@users.noreply.github.com> Date: Sat, 29 Jun 2024 00:02:32 +0200 Subject: [PATCH] Replace Where-Object with .where Method (#2212) * initialize Windev branch * Formatting * more Formatting * fix applications * init * remove timer * Compile Winutil * revert winutil.ps1 * revert winutil.ps1 * update Get Winutilvariables to use .where method --------- Co-authored-by: Marterich --- functions/private/Get-WinUtilVariables.ps1 | 4 +--- scripts/main.ps1 | 9 ++++----- winutil.ps1 | 2 +- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/functions/private/Get-WinUtilVariables.ps1 b/functions/private/Get-WinUtilVariables.ps1 index d19a3e9e..56f36eb9 100644 --- a/functions/private/Get-WinUtilVariables.ps1 +++ b/functions/private/Get-WinUtilVariables.ps1 @@ -11,9 +11,7 @@ function Get-WinUtilVariables { [Parameter()] [string[]]$Type ) - - $keys = $sync.keys | Where-Object { $_ -like "WPF*" } - + $keys = ($sync.keys).where{ $_ -like "WPF*" } if ($Type) { $output = $keys | ForEach-Object { Try { diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 48bf2b67..7b3b4df3 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -10,7 +10,7 @@ $InitialSessionState = [System.Management.Automation.Runspaces.InitialSessionSta $InitialSessionState.Variables.Add($hashVars) # Get every private function and add them to the session state -$functions = Get-ChildItem function:\ | Where-Object {$_.name -like "*winutil*" -or $_.name -like "*WPF*"} +$functions = (Get-ChildItem function:\).where{$_.name -like "*winutil*" -or $_.name -like "*WPF*"} foreach ($function in $functions){ $functionDefinition = Get-Content function:\$($function.name) $functionEntry = New-Object System.Management.Automation.Runspaces.SessionStateFunctionEntry -ArgumentList $($function.name), $functionDefinition @@ -276,7 +276,7 @@ Add-Type @" "@ } - foreach ($proc in (Get-Process | Where-Object { $_.MainWindowTitle -and $_.MainWindowTitle -like "*titus*" })) { + foreach ($proc in (Get-Process).where{ $_.MainWindowTitle -and $_.MainWindowTitle -like "*titus*" }) { # Check if the process's MainWindowHandle is valid if ($proc.MainWindowHandle -ne [System.IntPtr]::Zero) { Write-Debug "MainWindowHandle: $($proc.Id) $($proc.MainWindowTitle) $($proc.MainWindowHandle)" @@ -392,11 +392,11 @@ Add-Type @" # Load Checkboxes and Labels outside of the Filter fuction only once on startup for performance reasons $filter = Get-WinUtilVariables -Type CheckBox -$CheckBoxes = $sync.GetEnumerator() | Where-Object { $psitem.Key -in $filter } +$CheckBoxes = ($sync.GetEnumerator()).where{ $psitem.Key -in $filter } $filter = Get-WinUtilVariables -Type Label $labels = @{} -$sync.GetEnumerator() | Where-Object {$PSItem.Key -in $filter} | ForEach-Object {$labels[$_.Key] = $_.Value} +($sync.GetEnumerator()).where{$PSItem.Key -in $filter} | ForEach-Object {$labels[$_.Key] = $_.Value} $allCategories = $checkBoxes.Name | ForEach-Object {$sync.configs.applications.$_} | Select-Object -Unique -ExpandProperty category @@ -499,6 +499,5 @@ Version :