# Friday, October 02, 2009

ArgumentTransformationAttributes are attached to function parameters. They intercept the value coming in and optionally transform it before it is assigned to the target parameter. This is how the powershell type system is enforced:

function Foo ( [string]$str ) { ... }
(gi function:foo).parameters.str.attributes
TypeId
------
System.Management.Automation.ArgumentTypeConverterAttribute
System.Management.Automation.ParameterAttribute

This type converter derives from ArgumentTransformationAttribute. It uses the public utility type [Management.Automation.LanguagePrimitives] (which is full of cool stuff btw) to coerce incoming types to the designated type constraint, in this case [string].

As an aside, you can use the credential attribute on a function parameter too:

function do-something ([system.management.automation.credential()]$cred) { $cred }
do-something # get-credential dialog pops up if $cred is not explicitly passed

And while a little strange but definitely empowering from a future extensibility point of view, you can decorate parameters with entirely inappropriate attributes:

function Foo ( [obsolete($true)][string]$bar ) { ... }

System.ObsoleteAttribute is used in C#/VB.NET to tell the compiler that usage of the decorated item should raise a warning (false) or error (true)

posted on Friday, October 02, 2009 8:46:51 PM (Eastern Daylight Time, UTC-04:00)  #    Comments [0] Trackback
Related posts:
PowerShell 2.0 – Partial Application of Functions and Cmdlets
PowerShell – The Patchwork of Paths, PSPaths and ProviderPaths
PowerShell - Why are keys in Hashtables sorted randomly?
PowerShell 2.0 - About Dynamic Parameters
PowerShell 2.0 – Introducing the PModem File Transfer Protocol
PowerShell 2.0 - Enabling Remoting with Virtual XP Mode on Windows 7

Referred by:
http://twitturls.com/ [Referral]
http://favit.com/ [Referral]
http://twitter.com/ [Referral]
http://iconfactory.com/twitterrific [Referral]
http://technorati.com/posts/Jrto5IABKs5AWf7_9jEdEtO5GeZ_WHhj... [Referral]
PowerShell (www.google.co.jp) [Referral]
powershell params attributes (www.google.com.mx) [Referral]
http://www.google.com/reader/view/ [Referral]
power shell call .net system function (www.google.com) [Referral]
http://www.powershellcommunity.org/Blogs/ExternalBlogs.aspx [Referral]
http://www.google.com/ig?hl=en&source=iglk [Referral]
http://powershell.com/cs/content/TwitterGrid.aspx [Referral]
powershell functions parameters (www.google.com) [Referral]
http://pipes.yahoo.com/pipes/pipe.info?_id=uAmYy9xq3BGHcV361... [Referral]
.NET Attribute of function (www.google.com) [Referral]
http://powertwitter.me/ [Referral]
function .net (www.google.co.za) [Referral]
google rss powershell (www.google.com) [Referral]
http://powershellcommunity.org/Blogs/ExternalBlogs.aspx [Referral]
powershell functions param (www.google.com) [Referral]
vb.net function parameter as type (www.google.de) [Referral]
view attribute powershell (www.google.com) [Referral]
.net attribute parameter (www.google.de) [Referral]
powershell call function (www.google.nl) [Referral]
http://my.yahoo.com/ [Referral]
powershell function + Param (www.google.com) [Referral]
powershell function (www.google.com.hk) [Referral]
powershell what is "@" "&" (www.google.com) [Referral]
powershell functions parameters (www.google.com) [Referral]
.net system attribute function parameter (www.google.de) [Referral]
.net function parameter with systemattribute (www.google.de) [Referral]
http://www.google.nl/ig?hl=nl&t=1 [Referral]
powershell parameters (www.google.com) [Referral]
cache:nnhp-9DKCwQJ:powershellcommunity.org/Blogs/ExternalBlogs.aspx PowerShell credentialattribute advanced function (74.125.95.132) [Referral]
powershell functions parameters (www.google.com) [Referral]
vb.net decorate a function (www.google.com) [Referral]
aspx attribute function (www.google.com) [Referral]
powershell function true false (www.google.co.uk) [Referral]
powershell parameters (www.google.com) [Referral]
create power shell function parameters (www.google.com) [Referral]
call .net function powershell (www.google.com) [Referral]
powershell function (www.google.nl) [Referral]
vb.net pass parameter to powershell (www.google.co.uk) [Referral]
.net attribute parameters (www.google.com) [Referral]
powershell pipe functions parameter (www.google.com) [Referral]
powershell function parameter file (www.google.be) [Referral]
powershell parameter (www.google.co.kr) [Referral]
call function through attribute .NET (www.google.com) [Referral]
vb.net and powershell (www.google.co.uk) [Referral]
powershell functions parameters (www.google.com) [Referral]
powershell function parameters (www.google.com) [Referral]
Power Shell Function (www.google.ru) [Referral]
vb.net execute function in attribute (www.google.si) [Referral]
parameters for function .net (www.google.com) [Referral]
function parameters type .net (www.google.co.in) [Referral]
powershell parameters (www.google.be) [Referral]
vb.net attributes on parameter (www.google.com) [Referral]
powershell parameters (www.google.com) [Referral]
attribute for parameters funtion vb.net (www.google.co.in) [Referral]
powershell [Parameter()] (www.google.com) [Referral]
function pass \parameters powershell (www.google.pl) [Referral]
powershell function param() $True $False (www.google.nl) [Referral]
aspx .Attributes[ (www.google.ca) [Referral]
powershell functions parameters (www.google.com) [Referral]
what are .net function attributes (www.google.com) [Referral]
windows 7 I attribute (www.google.com) [Referral]
function parameter .net (www.google.com) [Referral]
func in attribute parameter (www.google.com) [Referral]
powershell function types (www.google.com.tr) [Referral]
http://www.netvibes.com/online_casinos [Referral]
powershell parameterized type (www.google.com) [Referral]
powershell parameters attributes (www.bing.com) [Referral]
powershell check pipe or param (www.google.com) [Referral]
types of function parameters .NET (www.google.co.in) [Referral]
c# .net function to powershell function (www.google.com) [Referral]
VB.Net decorating functions (www.google.com) [Referral]
powershell function param (hk.search.yahoo.com) [Referral]
http://www.netvibes.com/ [Referral]
calling a function with parameters in powershell (www.google.com.au) [Referral]
.net function attributes (www.google.com) [Referral]
call .net function in power shell (search.yahoo.com) [Referral]
vb.net adding power shell parameters (www.google.com.au) [Referral]
vb.net attribute parameters function (www.bing.com) [Referral]
how to call vb.net function on attribute (www.google.co.in) [Referral]
powershell function attribute (www.google.se) [Referral]
powershell function (www.bing.com) [Referral]
powershell create function (www.bing.com) [Referral]
powershell function (www.bing.com) [Referral]
powershell functions parameters (www.bing.com) [Referral]
powershell piping ".net" (www.bing.com) [Referral]
System.Management.Automation.ArgumentTypeConverterAttribute (www.bing.com) [Referral]
.net functions attributes (www.google.es) [Referral]
.net attributes parameters (www.google.lv) [Referral]
powershell function parameters (search.yahoo.com) [Referral]
SharePoint Powershell passing parameters (www.bing.com) [Referral]
http://delicious.com/Jaykul?utm_source=feedburner&utm_medium... [Referral]
powershell function parameters (www.bing.com) [Referral]
http://www.google.com/reader/view/?hl=en&tab=wy [Referral]
http://www.google.com/reader/public/atom/user/13309556466516... [Referral]
type converter powershell parameter (www.google.nl) [Referral]
powershell attributes (www.google.com) [Referral]
types of parameters in .NET (www.google.co.in) [Referral]
aspx function with parameters (www.google.com.pe) [Referral]
vb.net in attribute parameter (www.google.com) [Referral]
powershell function parameters (www.google.com) [Referral]
passing parameter to function+powershell (www.google.com.mx) [Referral]
powershell function (www.bing.com) [Referral]
powershell true false function (www.google.com) [Referral]
powershell get functions .net (www.google.de) [Referral]
powershell credential parameter (www.google.com) [Referral]
powershell function parameter type (www.google.com) [Referral]
powershell call function with parameters +param (www.google.co.uk) [Referral]
credential parameter function powershell (www.google.com) [Referral]
params powershell (www.google.com) [Referral]
powershell function parameters (www.google.no) [Referral]
param params powershell (www.google.fr) [Referral]
call powershell function from VB.NET (www.bing.com) [Referral]
powershell 2 function param (www.google.com) [Referral]
powershell credential attribute (www.google.ca) [Referral]
powershell asp.net adding parameter (www.google.se) [Referral]
powershell execute .net functions (www.google.ro) [Referral]
powershell call .net functions (www.google.com) [Referral]
powershell call function (www.google.de) [Referral]
powershell function "&" (www.google.com.hk) [Referral]
aspx <% %> Function with parameters (www.google.ca) [Referral]
vb.net function attributes (search.yahoo.com) [Referral]
http://assist.babylon.com/babylonassista/dnsassist/main?acti... [Referral]
http://www.baidu.com/s?bs=powershell+%B5%F7%D3%C3%BA%AF%CA%F... [Referral]
powershell function attribute (www.bing.com) [Referral]
powershell funtion (www.bing.com) [Referral]
powershell function attributes (www.bing.com) [Referral]
.net attribute params (www.google.co.uk) [Referral]
powershell parameters vb.net (www.google.co.il) [Referral]
function parameter attribute vb.net (www.google.com.pk) [Referral]
http://guide.opendns.com/controller.php?url=powershell+funct... [Referral]
funtion powershell (www.google.fr) [Referral]
powershell gi function (www.google.at) [Referral]
Passing parameters in Powershell through VB.net (www.google.com) [Referral]
powershell parameter attribute (www.google.com) [Referral]
powershell function parameters (www.google.com) [Referral]
attributes powershell (www.google.com) [Referral]
powershell parameters function passing .net objects (www.bing.com) [Referral]
powershell function (www.bing.com) [Referral]
get function params in vb .net (www.google.com) [Referral]
.net attributes in powershell (www.google.co.uk) [Referral]
powershell parameter attribute (www.google.com) [Referral]
powershell+php+pass params (www.google.co.uk) [Referral]
powershell function with params (www.google.co.uk) [Referral]
passing parameters pipe powershell function (www.google.com) [Referral]
powershell function string param (de.altavista.com) [Referral]
powershell how to see attributes (www.google.com.tr) [Referral]
http://www.diigo.com/bookmark/http%3A//www.nivot.org/2009/10... [Referral]
ArgumentTransformationAttribute (www.google.de) [Referral]
vb.net powershell parameters (www.google.com) [Referral]
powershell passing parameters to function (www.google.co.uk) [Referral]
windows 7 powershell attrib (www.google.com) [Referral]
powershell function referral (www.google.fr) [Referral]
.net functions in powershell (www.google.com) [Referral]
.net shell function (www.bing.com) [Referral]
http://yandex.ru/yandsearch?text=c3+attribute+%D1%82%D1%83%D... [Referral]
.net call function attributes (www.google.co.uk) [Referral]
powershell function cache -velocity (www.google.com) [Referral]
powershell param pipe (www.google.com) [Referral]
http://www.baidu.com/s?wd=vb+Parameters+.net [Referral]
powershell 2.0 parameter attributes (www.google.co.uk) [Referral]
powershell blogs (www.bing.com) [Referral]
vb.net function parameter attributes (www.google.be) [Referral]
powershell .net parameter (www.google.ca) [Referral]
powershell pipe function parameter (www.google.nl) [Referral]
powershell function parameters (www.google.co.uk) [Referral]
vb.net parameter attribute (www.google.com.my) [Referral]
powershell function parameter (www.google.co.uk) [Referral]
Func attribute .net (www.google.com) [Referral]
powershell passing parameters pipe (www.bing.com) [Referral]
.net pass parameters to attributes (www.google.bg) [Referral]
powershell function parameters (www.bing.com) [Referral]
sharepoint powershell FBA credentials (www.bing.com) [Referral]
powershell function as a parameter (www.bing.com) [Referral]
powershell 2.0 "function parameters" (www.google.com) [Referral]
"powershell 2" param function (www.google.com) [Referral]
pass net time \\ to powershell (www.bing.com) [Referral]
Comments are closed.