Severity: Warning
Summary
The file header declares PowerShell 2.0 compatibility, but the body uses a parameter that only exists in PowerShell 3.0+.
File and lines
setup/taskschd/Get-ServyLastErrors.ps1
Header claim (lines 13–21):
.NOTES
Author : Akram El Assas
Project : Servy
Requirements:
- PowerShell 2.0 or later.
- Windows Vista / Windows Server 2008 or newer.
- Note: This script is NOT compatible with Windows XP or Server 2003
due to the dependency on the Get-WinEvent cmdlet.
Incompatible usage (line 62):
$errors = @(Get-WinEvent -FilterHashtable $filter -ErrorAction Stop)
Explanation
Get-WinEvent itself was introduced in PowerShell 2.0, but the -FilterHashtable parameter was added in PowerShell 3.0. On a Vista/2008 box that still runs stock PS 2.0, this call fails with a ParameterBindingException, not a "no events" case — so the existing NoMatchingEventsFound catch branch does not help.
The author is clearly aware of PS 2.0 differences elsewhere in the file — line 37 has a deliberate $PSScriptRoot vs $MyInvocation.MyCommand.Definition fallback for the same reason — so this looks like an oversight rather than a policy choice.
Note: this is a different concern from the previously-closed #611, which addressed the Vista-vs-XP part of the header. That fix clarified the OS requirement but left the PS-version claim intact.
Suggested fix
Either:
-
Drop the PS 2.0 claim from the header to match the actual floor (several sibling scripts already declare #requires -Version 5.0 or similar), e.g.:
Requirements:
- PowerShell 3.0 or later.
- Windows Vista / Windows Server 2008 or newer.
Optionally add #Requires -Version 3.0 at the top so the failure is clean instead of a runtime parameter-binding error.
-
Or rewrite the query in PS 2.0–compatible form using Get-EventLog:
$errors = Get-EventLog -LogName Application -Source 'Servy' -EntryType Error |
Where-Object { (-not $LastProcessed) -or ($_.TimeGenerated -gt $LastProcessed) }
(Note: Get-EventLog uses the legacy Event Log API and is slower on large logs — option 1 is usually the cleaner choice for a script that already requires Vista+.)
Severity: Warning
Summary
The file header declares PowerShell 2.0 compatibility, but the body uses a parameter that only exists in PowerShell 3.0+.
File and lines
setup/taskschd/Get-ServyLastErrors.ps1Header claim (lines 13–21):
.NOTES Author : Akram El Assas Project : Servy Requirements: - PowerShell 2.0 or later. - Windows Vista / Windows Server 2008 or newer. - Note: This script is NOT compatible with Windows XP or Server 2003 due to the dependency on the Get-WinEvent cmdlet.Incompatible usage (line 62):
Explanation
Get-WinEventitself was introduced in PowerShell 2.0, but the-FilterHashtableparameter was added in PowerShell 3.0. On a Vista/2008 box that still runs stock PS 2.0, this call fails with aParameterBindingException, not a "no events" case — so the existingNoMatchingEventsFoundcatch branch does not help.The author is clearly aware of PS 2.0 differences elsewhere in the file — line 37 has a deliberate
$PSScriptRootvs$MyInvocation.MyCommand.Definitionfallback for the same reason — so this looks like an oversight rather than a policy choice.Note: this is a different concern from the previously-closed #611, which addressed the Vista-vs-XP part of the header. That fix clarified the OS requirement but left the PS-version claim intact.
Suggested fix
Either:
Drop the PS 2.0 claim from the header to match the actual floor (several sibling scripts already declare
#requires -Version 5.0or similar), e.g.:Optionally add
#Requires -Version 3.0at the top so the failure is clean instead of a runtime parameter-binding error.Or rewrite the query in PS 2.0–compatible form using
Get-EventLog:(Note:
Get-EventLoguses the legacy Event Log API and is slower on large logs — option 1 is usually the cleaner choice for a script that already requires Vista+.)