For example:
function TestThis()
{
[MySpecialCustomAttribute]
[CmdletBinding()]
Param(...)
Process{...}
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, of course you can!
Any type derived from
Attributewhich allowsUsageType.All(orUsageType.Class) can be used on the function itself (i.e. aboveParam)Any type derived from
Attributewhich allowsUsageType.PropertyorUsageType.Fieldusage can be used on parameters themselves or variables.It’s not uncommon to just be lazy and use
UsageType.All(e.g. the built inOutputTypeattribute does that).You can even write them in PowerShell classes now
See more examples on Kevin Marquette‘s blog.
There’s an older example here showing how to do it in PowerShell 4 and earlier using Add-Type, although it’s a little out of date now, because the particular example it shows has been integrated into PowerShell 6 and is no longer needed
There are also videos