View Single Post
Old 01-15-2007   #8 (permalink)
Nick Howell


 
 

Re: Change Help default behaviour

Didn't think of using a fully qualified cmdlet; nice trick!

Nick

Andrew Watt [MVP] wrote:
> Oops. Typo in my earlier post. The code that gives an error due to a
> potentially infinite loop should read :
>
> PS Function:\> function get-process {
>>> get-process sql*
>>> }
>>>

>
> Andrew Watt MVP
>
> On Mon, 15 Jan 2007 14:21:27 +0000, "Andrew Watt [MVP]"
> <SVGDeveloper@aol.com> wrote:
>
>> Nick,
>>
>> You can already do what you want using a slightly different technique.
>>
>> Suppose, as a simple example, you want to make the get-process cmdlet
>> behave like
>>
>> get-process -name sql*
>>
>> Do it like this:
>>
>> PS Function:\> function get-process {
>>>> Microsoft.PowerShell.Management\get-process sql*
>>>> }
>>>>

>> PS Function:\> get-process
>>
>> Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
>> ------- ------ ----- ----- ----- ------ -- -----------
>> 383 11 9400 1820 98 12.31 5604 SQLAGENT90
>> 416 6 37968 5124 68 51.88 468 sqlbrowser
>> 332 39 36728 20736 1495 12.09 3484 sqlservr
>> 599 77 160552 135432 1719 197.38 3528 sqlservr
>> 624 18 49316 52168 288 52.66 4476 SqlWb
>> 83 2 940 2220 20 8.45 748 sqlwriter
>>
>> You need to qualify the name inside the curly braces or you get a loop
>> that terminates with an error:
>>
>> PS Function:\> function get-process {
>>>> get-process
>>>> }
>>>>

>> PS Function:\> get-process
>> The script failed due to call depth overflow. The call depth reached
>> 101 and the maximum is 100.
>>
>> When you want to return to default behaviour simply type:
>>
>> del function:get-process
>>
>> I hope that helps.
>>
>> Andrew Watt MVP
>>
>> On Sun, 14 Jan 2007 16:25:43 -0600, Nick Howell
>> <msnews.1.nlhowell@spamgourmet.com> wrote:
>>
>>> I would like to request a feature whereby you can set defaults for cmdlet parameters. Something like this, maybe:
>>>
>>> Set-CommandDefault -Command:<cmdlet, function, filter> -Parameter:<parameter name> -Value:<some object>
>>>
>>> Or perhaps put it in a ps1xml file.

My System SpecsSystem Spec