![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Calling parameters as a variable Can something like this be made to work? PS C:\> $string="-detailed" PS C:\> get-help get-command $string Get-Help : A parameter cannot be found that matches parameter name '-detailed'. At line:1 char:9 + get-help <<<< get-command $string PS C:\> get-help get-command "$string" Get-Help : A parameter cannot be found that matches parameter name '-detailed'. At line:1 char:9 + get-help <<<< get-command "$string" |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: Calling parameters as a variable Hi Marco, > Can something like this be made to work? > > PS C:\> $string="-detailed" > PS C:\> get-help get-command $string Not sure why your version does not work, but this one does: PS> $string="-detailed" PS> invoke-expression "get-help get-command $string" Or if you prefer aliases: PS> iex "get-help get-command $string" hth Max |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: Calling parameters as a variable I'm presuming you want to do this to propagate a switch parameter in a function? You could use invoke-expression however PowerShell has explicit support for exactly this scenario. Switch parameters normally don't take arguments but if the name is specified with a colon, then they do. This allows you to "forward" a function switch parameter to a cmdlet switch parameter. Here's an example: function my-help ($topic, [switch] $noisy) { get-help $topic -detailed: $noisy } In this function, the function parameter $noisy is used to control the -detailed: switch on get-help. -bruce -- Bruce Payette [MSFT] Windows PowerShell Technical Lead Microsoft Corporation This posting is provided "AS IS" with no warranties, and confers no rights. Visit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShell Visit the Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scr.../hubs/msh.mspx My Book: http://manning.com/powershell "Marco Shaw" <marco@Znbnet.nb.ca> wrote in message news:OjX0dv0FHHA.4688@TK2MSFTNGP04.phx.gbl... > Can something like this be made to work? > > PS C:\> $string="-detailed" > PS C:\> get-help get-command $string > Get-Help : A parameter cannot be found that matches parameter name > '-detailed'. > At line:1 char:9 > + get-help <<<< get-command $string > PS C:\> get-help get-command "$string" > Get-Help : A parameter cannot be found that matches parameter name > '-detailed'. > At line:1 char:9 > + get-help <<<< get-command "$string" > |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: Calling parameters as a variable "Bruce Payette [MSFT]" <brucepay@microsoft.com> wrote in message news:eGWUoa2FHHA.3468@TK2MSFTNGP04.phx.gbl... > I'm presuming you want to do this to propagate a switch parameter in a > function? You could use invoke-expression however PowerShell has explicit > support for exactly this scenario. Switch parameters normally don't take > arguments but if the name is specified with a colon, then they do. This > allows you to "forward" a function switch parameter to a cmdlet switch > parameter. Here's an example: > > function my-help ($topic, [switch] $noisy) > { > get-help $topic -detailed: $noisy > } > > In this function, the function parameter $noisy is used to control > the -detailed: switch on get-help. I've said it before and I'll say it again, that's one of those little features of PoSh that I love. -- Keith |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Bad Variable Type when calling via COM | Colin Bowern | PowerShell | 11 | 06-24-2008 12:39 PM |
| Calling ID | Mary Anne | Vista mail | 3 | 02-09-2008 09:04 PM |
| Passing parameters to a cmdlet in a variable | Alastair Smith | PowerShell | 1 | 02-08-2008 06:29 AM |
| Passing dynamic number of parameters to a function as a variable | Robin Moffatt | PowerShell | 10 | 01-30-2008 12:38 AM |
| How can I ensure that a variable is a built-in powershell variable? | Sung M Kim | PowerShell | 7 | 09-22-2006 06:28 PM |