# Sunday, January 17, 2010

Did you know that when you run Get-Help against a cmdlet to find out about its parameters, you might not be getting the whole truth? Certain cmdlets, especially those that operate on providers (FileSystem, Certificate, Registry etc) can adopt new parameters on the fly, depending on the path they are acting on. For example, when use you Get-Content on the file system (drive c: etc), it gets three new parameters in addition to the static ones listed by Get-Help (but more about this later): Delimiter, Encoding and Wait.

Determining Dynamic Parameters using Get-Help

Get-Help has a new parameter, –Path, which lets you give the help system some context for determining dynamic parameters:

-Path <string>
    Gets help that explains how the cmdlet works in the specified provider path. Enter a Windows PowerShell provider path.

    This parameter gets a customized version of a cmdlet help topic that explains how the cmdlet works in the specified Windows PowerShell provider path. This parameter is effective only for help about a provider cmdlet and only when the provider includes a custom version of the provider cmdlet help topic.

    To see the custom cmdlet help for a provider path, go to the provider path location and enter a Get-Help command or, from any path location, use the Path parameter of Get-Help to specify the provider path. For more information, see about_Providers.

Determining Dynamic Parameters using Get-Command

Get-Command has a new parameter, –ArgumentList, which acts similarly to unveil what dynamic parameters might be attached to a cmdlet for a given parameterset and path/literalpath if available on the chosen cmdlet. I’ve written a simple function that takes a cmdlet name as an argument and will display all of the dynamic parameters available for a cmdlet for each distinct provider:

# this function will pass a drive name in position 0 as an unnamed argument
# most path-oriented cmdlets accept this binding
function Get-DynamicParameter {
    param(        
        [string]$command
    ) 
  
    $parameters = @{}
    get-psdrive | sort -unique provider | % {
        $parameters[$_.provider.name] = gcm $command -args "$($_.name):" | % {
            $c = $_; @($_.parameters.keys) | sort | ? {
                $c.parameters[$_].isdynamic
            }
        }
    }
    $parameters    
}

Example use:

PS> Get-DynamicParameter get-content

Name                           Value
----                           -----
Alias
FileSystem                     {Delimiter, Encoding, Wait}
AssemblyCache
Registry
Environment
WSMan
Certificate
FeedStore
Function
Variable
PscxSettings

NOTE: when you don’t pass any context parameters to get-command via –argumentlist, it will take your current location as the context for dynamic parameters (if any are found.) So running get-command from c:\ instead hklm:\ will give you the additional parameters Delimiter, Encoding and Wait.

Have fun!

posted on Sunday, January 17, 2010 9:33:04 PM (Eastern Standard Time, UTC-05: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 – Introducing the PModem File Transfer Protocol
PowerShell 2.0 - Enabling Remoting with Virtual XP Mode on Windows 7
PowerShell 2.0 goes RTM for ALL Platforms

Referred by:
http://twitter.com/ [Referral]
http://www.google.com/reader/view/ [Referral]
http://bit.ly/4ZQfBA [Referral]
http://untiny.me/ [Referral]
http://www.powershell-ag.de/ps/ [Referral]
http://twitter.com/MakcoH/favorites [Referral]
http://iconfactory.com/twitterrific [Referral]
powershell (tweetgrid.com) [Referral]
http://twitturls.com/ [Referral]
http://www.google.de/reader/view/?tab=my [Referral]
http://seesmic.com/web/index.html?locale=en [Referral]
powershell dynamic param (www.google.co.uk) [Referral]
PowerShell (blogsearch.google.co.jp) [Referral]
http://www.lmodules.com/opensocial/ifr?url=http%3A%2F%2Fwww%... [Referral]
http://pipes.yahoo.com/pipes/pipe.info?_id=uAmYy9xq3BGHcV361... [Referral]
http://powershell.com/cs/content/TwitterGrid.aspx [Referral]
http://www.powershellcommunity.org/Blogs/ExternalBlogs.aspx [Referral]
powershell -pattern (www.google.com) [Referral]
http://twitter.com/conduityoursite [Referral]
http://technorati.com/tag/PowerShell [Referral]
powershell @ (www.google.com) [Referral]
powershell arguments param (www.google.com) [Referral]
dynamic parameters powershell (www.google.com) [Referral]
powershell param path (www.google.com) [Referral]
http://www.google.nl/ig?hl=nl&t=1 [Referral]
http://feedjit.com/news/CN/qingqu/ [Referral]
http://twitter.com/halr9000/statuses/7970602443 [Referral]
powershell 2.0 certificate path (www.google.com) [Referral]
powershell 2.0 param (www.google.ca) [Referral]
-eq powershell (www.google.co.uk) [Referral]
powershell 2.0 parameters (www.google.com) [Referral]
powershell 2.0 param (www.google.com) [Referral]
http://delicious.com/halr9000/powerscripting+todo [Referral]
powershell 2.0 required parameters (www.google.se) [Referral]
http://powershell-cz.blogspot.com/2010/01/get-psnews-week-eq... [Referral]
powershell 2.0 cmdlet parameters (www.google.com) [Referral]
powershell provider (www.google.co.kr) [Referral]
powershell parameters (www.google.com.au) [Referral]
powershell 2.0 parameter (www.google.com) [Referral]
rss 2.0 parameter (www.google.es) [Referral]
powershell using -ne multiple values (www.google.com) [Referral]
cmdlet dynamic parameters (www.google.co.uk) [Referral]
is lmodules.com/referral (www.google.co.uk) [Referral]
http://genericwpthemes.com/ [Referral]
powershell param( [Parameter (www.google.es) [Referral]
powershell dynamic parameter (www.google.com) [Referral]
http://tweetmeme.com/story/455813033/nivot-ink-powershell-20... [Referral]
http://powershell.com/cs/forums/t/3404.aspx [Referral]
powershell 2.0 param (www.google.co.uk) [Referral]
dynamicparam + powershell (www.google.de) [Referral]
dynamic parameter on the fly (www.google.com) [Referral]
powershell 2.0 PARAM (www.google.ca) [Referral]
c dynamic parameters (www.google.com) [Referral]
powershell param (www.google.com) [Referral]
powershell (technorati.com) [Referral]
http://www.vigrx-plus.net/ [Referral]
powershell 2.0 parameters (www.google.co.uk) [Referral]
powershell dynamicparam (www.google.com) [Referral]
powershell param (www.google.ca) [Referral]
param powershell 2.0 (www.google.ca) [Referral]
http://www.netvibes.com/missoni [Referral]
powershell 2.0 param (www.google.ch) [Referral]
powershell DynamicParam (www.google.com) [Referral]
9f769a408dd811a059e8cb664251 (cache.baidu.com) [Referral]
parameters.keys gcm command isdynamic (www.google.com) [Referral]
powershell 2.0 parameters (www.google.com) [Referral]
powershell parameters (www.google.com) [Referral]
powershell dynamic function name (www.google.com) [Referral]
param powershell (www.google.com) [Referral]
http://pauerschell.blogspot.com/2010/02/2nd-improvement-to-a... [Referral]
dynamic cmdlet powershell (www.bing.com) [Referral]
dynamic parameters in powershell (www.bing.com) [Referral]
powershell 2.0 param string (www.google.com) [Referral]
powershell parameters pass dynamic values (www.bing.com) [Referral]
powershell 2.0 param (www.google.com) [Referral]
http://delicious.com/PowerShellJedi [Referral]
powershell param (www.google.de) [Referral]
powershell 2.0 script function with dynamic parameters (www.google.com) [Referral]
powershell param (www.google.com) [Referral]
powershell dynamic parameter (www.google.com) [Referral]
multiple arguments powershell (www.google.se) [Referral]
http://powershellcommunity.org/Blogs/ExternalBlogs.aspx [Referral]
powershell 2.0 [Parameter (www.google.de) [Referral]
powershell dynamic parameters (www.bing.com) [Referral]
powershell call dynamic function name (www.google.com.au) [Referral]
dynamic powershell parameters (www.bing.com) [Referral]
http://ff.im/-eywBk [Referral]
param powershell (www.google.dk) [Referral]
powershell path for my fovorites in XP (www.google.com) [Referral]
powershell param (www.google.com) [Referral]
dynamic get param (www.google.lv) [Referral]
powershell dinamic parameter help function (www.google.com) [Referral]
powershell dynamic parameter in help section of functions (www.google.com) [Referral]
powershell 2.0 functions param (www.google.com) [Referral]
powershell parameters (www.google.com) [Referral]
get http content powershell 2.0 (www.google.com) [Referral]
powershell parameters (www.google.es) [Referral]
powershell param (www.google.com) [Referral]
powershell 2.0 working with functions (www.google.ca) [Referral]
dynamicparam powershell (www.google.ca) [Referral]
powershell parameters (www.google.pl) [Referral]
dynamic context parameters visual studio (www.google.com) [Referral]
powershell referral (www.google.co.uk) [Referral]
http://www.netvibes.com/cheapautoinsurancequote [Referral]
PowerShell Dynamic Parameters (www.google.com.by) [Referral]
powershell parameters (www.google.co.uk) [Referral]
powershell 2.0 param (www.google.com.au) [Referral]
9862d015d9c443eb1bfbc7710a4c (cache.baidu.com) [Referral]
lmodules.com/opensocial/ifr (www.google.com) [Referral]
powershell 2.0 parameter variable (www.google.co.jp) [Referral]
OpenID
Please login with either your OpenID above, or your details below.
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview