Skip to content

Get-JobList Filter Non-asterisk Wildcard Character Handling #9600

@mattcargile

Description

@mattcargile

Verified issue does not already exist?

I have searched and found no existing issue

What error did you receive?

If users, use any other wildcard character aside from asterisk, there will be unexpected behavior and the pattern matching will switch to -eq or -ne instead of -like or -notlike. There is also the issue of jobs with an asterisk in their name.

Steps to Reproduce

$sqli = 'sqli'
New-DbaAgentJob -SqlInstance  $sqli -Job 'Filter'
Find-DbaAgentJob -SqlInstance $sqli -JobName filte?

Please confirm that you are running the most recent version of dbatools

2.1.28 

( Version not as relevant as this issue exists in the latest commit on the development branch as of this message )

Other details or mentions

Consider the below class and method instead.

[WildcardPattern]::ContainsWildcardCharacters( 'hi`?')

Use in the below code paths for $jFilter and $sFilter.

foreach ($jFilter in $JobFilter) {
if ($jFilter -match '`*') {
if ($Not) {
$job | Where-Object Name -NotLike $jFilter
} else {
$job | Where-Object Name -Like $jFilter
}
} else {

foreach ($sFilter in $StepFilter) {
if ($sFilter -match '`*') {
if ($Not) {
$stepFound = $job.JobSteps | Where-Object Name -NotLike $sFilter
if ($stepFound.Count -gt 0) {
$job
}
} else {

What PowerShell host was used when producing this error

PowerShell Core (pwsh.exe)

PowerShell Host Version

Name                           Value
----                           -----
PSVersion                      7.5.0
PSEdition                      Core
GitCommitId                    7.5.0
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

SQL Server Edition and Build number

Microsoft SQL Server 2017 (RTM-CU20) (KB4541283) - 14.0.3294.2 (X64) 
	Mar 13 2020 14:53:45 
	Copyright (C) 2017 Microsoft Corporation
	Standard Edition (64-bit) on Windows Server 2012 R2 Standard 6.3 <X64> (Build 9600: ) (Hypervisor)

.NET Framework Version

.NET 9.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions