-
Notifications
You must be signed in to change notification settings - Fork 389
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
Member within filter incorrectly marked as alias for Get-Member #1325
Comments
Hmm, interesting, I need to look at the AST first to see if we can do something about it, thanks for reporting it in the meantime |
A script block is a script block, so at parse time, 'member' appears as a command name, only at run time does the rules change, and then the rules can be defined by each cmdlet, if they so choose, thus its really impossible to second guess the intent. The only useful option might be to have an option to ignore certain errors when they appear within a script block argument of a command. ?? |
@bergmeister, is it possible that PSScriptAnalyzer could detect that the |
This is how the AST looks like. It's just a The only way to 'know' is to hard-code a check for the |
@msftrncs hits the nail on the head. The rule's working correctly, and overriding In another case I would say this should be suppressed on a per-line or per-block level. However, I know the AD module has a number of these DSL uses. If it's common to (ab)use the |
It's safe to assume most AD administrators have to use -Filter which is mandatory in most cases. The only question is how many things PSScriptAnalyzer will mark as bad. |
Yes, but why not have the parameter value as a string, because that's what it is at the end. It looks like PowerShell syntax but it actually isn't, it is its own DSL. The only reason that I can think of, is that this way, PowerShell could protect your from injection vulnerabilities a bit more compared to a interpolated strings because it has to go through the PowerShell parser. |
Actually it's probably me, misusing Filter syntax. Get-ADGroup -Filter 'GroupCategory -eq "Security' Works... |
Maybe the right answer is a rule that detects scriptblocks where a string should be used 😁 |
It doesn't help that the documentation uses the scriptblock notation in several places. https://docs.microsoft.com/en-us/powershell/module/activedirectory/get-adgroup. One might want to point out, that ActiveDirectory filters have operators that PowerShell's language does not, but fortunately most script block filters appear as a command invocation to the parser, so the operators become parameters, so no errors result during parsing. Syntax highlighting will definitely be wrong though. People probably like script blocks because they think they are getting highlighting. However, in editors, the user would get the benefit of variable completions, but filter member and operator completions would either be incorrect or incomplete, unless the editor/extension recognizes the context. I couldn't find the 'about_ActiveDirectory_Filters' topic, but what should be made clear in that topic, is that variable expansion should be avoided, for injection reasons, so use either a script block or a literal string, not a interpolated/expandable string. |
Yes, and they should continue to. But things like
Yeah I meant to mention this earlier when I looked this up. It seems that when these cmdlets were created, they were designed to have a weird DSL in arguments that looks like PowerShell and now the documentation is misleading. Perhaps this is just down to a miscommunication at some point, but it worries me. I suppose the DSL was to put other operators in or something (although there are other ways to do things like that...)
Although that's not possible everywhere, it should be for cmdlet parameters on cmdlets that are loaded loaded and have sensible parameter types (this info should also be in the compatibility profiles actually...)
Do you mean in the PowerShell docs? The AD module is entirely external to PowerShell and implements this filter DSL on its own. PowerShell has no knowledge of this filter language unfortunately. This language seems to be documented under the -Filter parameter. |
Should we start updating docs instead? |
Correct, but, the -Filter parameter says to |
Environment data
Not sure if this can be addressed thou. Just posting just in case this is indeed a bug.
The text was updated successfully, but these errors were encountered: