ironmansoftware / powershell-universal

Issue tracker for PowerShell Universal
https://powershelluniversal.com
36 stars 4 forks source link

PowerShell filter keyword is not recognized #4001

Open kp-bit opened 4 days ago

kp-bit commented 4 days ago

Description of Issue

The filter keyword is no longer recognized in PSU v5, it was working fine in the beta but after upgrading it no longer works. We can get around it for now by using function instead as we only have v5 on a test server currently.

More information: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_functions?view=powershell-7.4#filters

Version

5.0.13

Severity

Medium

Hosting Method

MSI (Windows Service)

Operating System

Windows

Database

SQLite

Features

Additional Environment data

Using integrated PowerShell

Screenshots/Animations

n/a

adamdriscoll commented 4 days ago

Are you just getting an error that the keyword isn't recognized? I tried this on the latest and it's working.

image

filter Get-ErrorLog ([switch]$Message)
{
  if ($Message) { Out-Host -InputObject $_.Message }
  else { $_ }
}

Get-WinEvent -LogName System -MaxEvents 100 | Get-ErrorLog -Message
kp-bit commented 3 days ago

The specific filter that fails is this one (works fine when changed to function):

filter GetPageUrl {
    $pageUrl = "$_".ToLower() -ireplace $script:rootPathPattern, '' -ireplace '\\', '/' -ireplace ' ', '-' -ireplace '\.ps1|\.udpage\.ps1', ''
    if ($pageUrl -eq '') {
        $pageUrl = '/'
    }
    $pageUrl
}

The error looks like this: image

adamdriscoll commented 5 hours ago

Where are you defining your function? If I define it in the functions tab, it works.

image

If I define it in the main app code, it doesn't.

image

I can fix that, but you should be able to work around by putting it in the function tab. It effectively is a module that is loaded into the app.