-
-
Notifications
You must be signed in to change notification settings - Fork 817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get-JobList
Filter Non-asterisk Wildcard Character Handling
#9600
Comments
I'd ask why on #9583 this didn't pop up but frankly I think that "featuring" this feature is out of scope. Either jobname includes SIMPLE pattern matching (aka asterisks) to make things easier for the people (as in quick-and-dirty), or another parameter needs to pop up which accepts a full-scale regex string that gets passed down, because then the issue would be "what if I have a job that has Right now the issue arises only for people having asterisks in their job names that can be .... directed elsewhere. |
This isn't about |
ahem, maybe I'm missing something, but it's not as easy as you'd like to be .... what about this ?
which is to say: one thing is -match ("full regex"), another, totally different, is -like |
Yeah it should throw on that. But yeah it is a bit more complicated with the error handling. What is worse, is us having some obscure matching syntax with its own quirks. Either we fully support Every command in Additionally, the docs should be updated in any case. dbatools/public/Find-DbaAgentJob.ps1 Lines 19 to 21 in ade9f6e
If you do agree with me in the end, we should add the [SupportsWildcards()] attribute to -JobName on Find-DbaAgentJob .
|
I concur docs should reflect what we support. |
Implementation of I agree that most users want I don't understand why we wouldn't just support the built-in comparisons and use the attributes to mark the support. We should use the wildcard method and if the pattern is wrong then we move to the next one with the same exception handling we use on other commands. Having a non-traditional |
ok, so let's establish two lines of things. One is "what we want to support", the other is "how can we support it". Also, we don't want to break existing scripts. Wanna go for "the way Get-DbaProcess" does (in c#), it probably involves decorating the parameter with something to detect errors in the pattern (didn't check, prolly
Then we can document that -JobName accepts wildcards the way If not, |
also, just to not forget, it's going to be ALWAYS a match by -like/-notlike and no more a match via -eq or -ne |
So first off, I don't know why we even have branching logic for Assuming there is something I missed from the above, here is the The attribute is only to alert the user for visibility. It doesn't appear to have any teeth with errors. AFAIK, it just sets the help section, supports wild cards, to true. From the stack trace, we would have to just at System.Management.Automation.WildcardPatternParser.Parse(WildcardPattern pattern, WildcardPatternParser parser)
at System.Management.Automation.WildcardPatternMatcher.MyWildcardPatternParser.Parse(WildcardPattern pattern, CharacterNormalizer characterNormalizer)
at System.Management.Automation.WildcardPatternMatcher..ctor(WildcardPattern wildcardPattern)
at System.Management.Automation.WildcardPattern.Init()
at System.Management.Automation.WildcardPattern.IsMatch(String input)
at Microsoft.PowerShell.Commands.ProcessBaseCommand.RetrieveMatchingProcessesByProcessName()
at Microsoft.PowerShell.Commands.ProcessBaseCommand.MatchingProcesses()
at Microsoft.PowerShell.Commands.GetProcessCommand.ProcessRecord()
at System.Management.Automation.CommandProcessor.ProcessRecord() Here is a demo function. Install-PSResource PSFramework
New-Item t.psm1 -conf -valu @'
function Get-SupportsWildcards {
[CmdletBinding()]
param (
[SupportsWildcards()]
[string]$Value
)
process {
try {
'abc' -like $Value
}
catch {
Stop-PSFFunction -Level Error -Message 'Failed like operator'
return
}
}
}
'@
Import-Module t.psm1 -force
Get-SupportsWildcards 'ab['
Get-Help Get-SupportsWildcards -Parameter Value
Remove-Module t.psm1
Remove_Item t.psm1 -conf It looks like only
I'm not sure what you mean by always be a match by |
yeah, maybe for this exchange slack could have been better, sometimes I prepared replies and altered them on the fly seeing your response coming in. As for "why do we do -eq/-ne vs -like/-notlike" is probably because who implemented it originally thought about "wildcards" as "asterisks". But this issue became later "I want the behaviour to match -like because the current one is non-standard". On this (non-standardi-ness), you have my vote. This CHANGES the behaviour. Repeating myself, while now a "-like" is done if "asterisk" is in the JobName, and -eq in other cases, the new behaviour, if we want this to match a "standard" behaviour, will always be done via "-like". No one can ever ask again to have a way to return a job named Back to us, forget about -eq, switch to -like, always. Good. But, we can't accept any string for -like, as some string do not end up being a usable -like. Also, we're assuming we wanna mirror Get-DbaProcess, which implements via c# (wildcard.isMatch) rather than pure-PS (-like ?).
so we're in "mix and match" mode ;-) . That being said, although strictly undocumented as accepting wildcards, it works, at least in this simple example
Back to the drawing board, if |
We are in agreement. I was wrong on a few things and I'm starting to see more of the challenge now. First off, it is a feature. Sorry to trivialize it and thanks for the patience. :-) It finally clicked when I considered the below example returning [wildcardpattern]::ContainsWildcardCharacters( 'hi`*') And previously I didn't realize the below example would be ok. The logic would use 'hi`*' -match '`*' So, I'm back to square one on how to handle it. I hadn't considered the "Exclude" logic either. I'm mostly of the opinion that |
I'm not in favour of defaulting everywhere to -like, jobs are usually named with prefixes/common names so this is a good usecase, but e.g. I wouldn't for Get-DbaDatabase. That being said I think it's time for a good poll to know how people think about this (specifically, jobs, and specifically, supporting the full breadth of wildcards instead of just "asterisks"). |
Ok cool, we can focus on just the jobs here maybe? The greater convo about wildcards and |
sure, don't see a great traction for it but, again, I'm not against "per se". |
I work interactively and I add aliases to Anyway, for So in the
This bit above I'm still thinking through. I'm pretty sure this would be ok as I think there is enough thrust in PowerShell itself of how wild cards work. I think users were always having to pass a backtick to escape an asterisk on ImplementationSo then this out dbatools/private/functions/Get-JobList.ps1 Lines 75 to 88 in 6b53882
Then the -ExcludeJobName would need to be converted from a -contains to a looped -like .dbatools/public/Find-DbaAgentJob.ps1 Lines 225 to 228 in 6b53882
|
And sorry I'm streaming more thoughts in. Stepping back from this command, is Sorry the aforementioned issue is kind of bleeding into this one. |
Giving more thought(s), Find-Dba* COULD support wildcards, Get-Dba* not. |
Yeah Shawn suggested this pattern back in 2023. I'm more against that. I would want |
I'd say 1 vote for the current pattern ("fancy searches via Find-, not Get-") from shawn vs 1 vote to change behaviour from you makes currentpattern+shawn win. Granted, "fancy" in here ATM is "support asterisks" and we (me and you) would like full-breadth for PS wildcards, which are a SUBSET of regex. Let's then fix this issue on the perimeter "let's fix Find-DbaAgentJob" and leave the rest up for discussion when the support behind the push to change the current pattern ("fancy searches via Find-, not Get-") is at least 20ish users. |
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
Please confirm that you are running the most recent version of dbatools
( 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.
Use in the below code paths for
$jFilter
and$sFilter
.dbatools/private/functions/Get-JobList.ps1
Lines 74 to 81 in 6b53882
dbatools/private/functions/Get-JobList.ps1
Lines 89 to 96 in 6b53882
What PowerShell host was used when producing this error
PowerShell Core (pwsh.exe)
PowerShell Host Version
SQL Server Edition and Build number
.NET Framework Version
The text was updated successfully, but these errors were encountered: