views:

87

answers:

1

I was wondering whether you could create your own .NET Attribute classes for PowerShell and use them in scripts e.g.

[DebugAttribute=true]
function DoSomeThing()
{
"I don't run in Release mode"
}

+1  A: 

You should be able to create your own attributes, but only for certain purposes - specifically validation and argument transformation.

From the MSDN Docs:

Snap-ins cannot create custom attributes that derive directly from CmdletMetadataAttribute because there is no public constructor. However, snap-ins can derive custom attributes from the ValidateArgumentsAttribute and ArgumentTransformationAttribute classes.

I have yet to create a cmdlet attribute and try it in an advanced function though.

Steven Murawski