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.

Get-Command should return full cmdletbinding details

See original GitHub issue

PowerShell Functions and Cmdlets can be decorated with the [CmdletBinding()] attribute with additional properties being able to be defined including SupportsShouldProcess, ConfirmImpact, DefaultParameterSetName,HelpURI, SupportsPaging, PositionalBinding

Currently we do not output details on this other than it being True if set and we don’t return it as false if it is not set and we should return it as either a simple False if not set at all or should return an object with the above properties as defined in the command

Steps to reproduce

Get-Command Disable-PNPDevice | Select -ExpandProperty CmdletBinding

Expected behavior

image image

Actual behavior

image image

Environment data

Whilst the screenshot’s are from ps v5.1 this also affects v7.0.0.preview.4

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:4
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
vexx32commented, Jul 27, 2021

You can get that one today as well, although it’s rather buried. Would be nice to get at it a bit more easily, but this does work for functions:

(Get-Command $functionName).ScriptBlock.Attributes.Where{$_ -is [CmdletBinding]}
1reaction
SeeminglySciencecommented, Jul 27, 2021

Note that for binary cmdlets it would be CmdletAttribute rather than CmdletBindingAttribute. I agree that both should provide this information more readily though.

For binary cmdlets, there is at least a quick workaround with public API’s:

(gcm Get-Command).ImplementingType.GetCustomAttributes([Management.Automation.CmdletAttribute])
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 >
Learn How PowerShell CmdletBinding Enhances Functions
In this tutorial, you will learn how to use the PowerShell CmdletBinding attribute to enhance functions and make them behave like cmdlets.
Read more >
How to test that a powershell function has a cmdletbinding ...
I'm trying out writing test-driven PowerShell code using Pester. Is there a way to test if a function has a certain CmdletBinding attribute, ......
Read more >
about Functions OutputTypeAttribute - PowerShell
FunctionInfo object that the Get-Command cmdlet returns. The OutputType attribute value is only a documentation note.
Read more >
Creating Safer PowerShell Functions
As you can see, [CmdletBinding()] is added to the param() block. But why? After all, the attribute is completely empty and defines no...
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