question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`ExternalScriptInfo` does not have property for `CmdletBinding` like `CmdletInfo`

See original GitHub issue

ExternalScriptInfo object should expose the property for CmdletBinding like CmdletInfo or FunctionInfo.

The only was to find if the ExternalScriptioInfo object has CmdletBinding attribute is to look through the attributes on the ScriptBlock.

But in the case of the following example, it is considered that the object has CmdletBinding with the explicit attribute.

param(
  [parameter()]
  $Path
)

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
daxian-dbwcommented, May 13, 2021

A more concrete example:

PS:17> cat .\test.ps1
##[CmdletBinding()]
param(
  [parameter()]
  $Path
)
PS:18>
PS:18> gcm .\test.ps1 -Syntax
.\test.ps1 (alias) -> C:\arena\tmp\playground\test.ps1

.\test.ps1 [[-Path] <Object>] [<CommonParameters>]

PS:19> $c = gcm .\test.ps1
PS:20> $c.ScriptBlock.Attributes
PS:21>

We can still get this information by enumerating all parameters from $c.Parameters and try to find a ParameterAttribute from any of them, but that’s just too much efforts. I think it would be nice to add the CmdletBinding property to ExternalScriptInfo, just like CmdletInfo and FunctionInfo.

1reaction
vexx32commented, May 13, 2021

@JamesWTruher Yeah that’s part of the point. A scriptblock is considered to have cmdletbinding if:

  • It actually has the [CmdletBinding()] attribute, OR
  • It has any [Parameter()] attributes on any of its parameters.

In other words, it’s quite a pain to find the information properly without the proper helper properties that are provided on FunctionInfo and CmdletInfo.

Read more comments on GitHub >

github_iconTop Results From Across the Web

about Functions CmdletBindingAttribute - PowerShell
The CmdletBinding attribute is an attribute of functions that makes them operate like compiled cmdlets written in C#.
Read more >
ExternalScriptInfo Class (System.Management.Automation)
Provides information for scripts that are directly executable by PowerShell but are not built into the runspace configuration.
Read more >
Param in CmdletBinding not mandatory and error ...
1 Answer 1 ... Your parameters are in separate parameter sets (only), so by design they cannot be used together. ... Since your...
Read more >
T
Ignore what was passed in, there are no common parameters if cmdlet binding is not used. shouldGenerateCommonParameters = false;.
Read more >
PowerShell-Docs/reference/docs-conceptual/lang-spec ...
A collection is a group of one or more related items, which need not have the same type. Examples of collection types are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found