Re: [MSH] Script parameter without a value
- From: "Jeff Jones [MSFT]" <jeffjon@xxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 7 Apr 2006 13:24:35 -0700
Note, you should be able to do this in your current drop.
--
Jeff Jones [MSFT]
Monad Development
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
"Jeff Jones [MSFT]" <jeffjon@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:%23QRDK%23nWGHA.752@xxxxxxxxxxxxxxxxxxxxxxx
That's it.
param ([switch]$LoggingEnabled)
--
Jeff Jones [MSFT]
Monad Development
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no
rights.
"Alex K. Angelopoulos [MVP]" <a k a @ m v p s . o r g> wrote in message
news:ugVjHDmWGHA.1200@xxxxxxxxxxxxxxxxxxxxxxx
What's the syntax for that going to be? Is the [Switch] just going to be
another type, so we'd do this?
Param ([Switch]$LoggingEnabled)
"Jeff Jones [MSFT]" <jeffjon@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:O8QnCrlWGHA.3660@xxxxxxxxxxxxxxxxxxxxxxx
Actually, in the next drop we changed bool so that an argument is
required just like any other type. Instead use [Switch] or
[SwitchParameter] to specify a parameter that defaults to true if
present and false if not.
--
Jeff Jones [MSFT]
Monad Development
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no
rights.
"Alex K. Angelopoulos [MVP]" <a k a @ m v p s . o r g> wrote in message
news:%236$EY8eWGHA.4960@xxxxxxxxxxxxxxxxxxxxxxx
Just change the Param statement to this:
Param ([bool]$LoggingEnabled)
By setting the type, you force MSH to treat it as a true-false value,
and specifying it on the commandline automatically makes it true, just
like a boolean cmdlet parameter. Without the [bool], MSH treats it as
an object - really, just "something" which could be a number, string,
or arbitrary object, and it expects some value.
"Dung K Hoang" <dunghoangkhac@xxxxxxxxxxx> wrote in message
news:ulX7%23bdWGHA.3624@xxxxxxxxxxxxxxxxxxxxxxx
Hi
I want to use in a script a parameter which may not accept a value.
For instance, my scrtipt can be called as:
Set_SomeDB -LoggingEnabled
I declare the param in the script as
{ Param ($LoggingEnabled)
....
}
When I call with the named param and specify a value, it works.
Set_SomeDB -LoggingEnabled $true
How I can simply run the script as Set_SomeDB -LoggingEnabled?
Thanks for any suggestion
/Dung
.
- References:
- [MSH] Script parameter without a value
- From: Dung K Hoang
- Re: [MSH] Script parameter without a value
- From: Jeff Jones [MSFT]
- Re: [MSH] Script parameter without a value
- From: Jeff Jones [MSFT]
- [MSH] Script parameter without a value
- Prev by Date: Re: Monad: Synthetic typing
- Next by Date: Re: Programatically upload a file to web folder
- Previous by thread: Re: [MSH] Script parameter without a value
- Next by thread: Re: Database backup on remote server
- Index(es):
Relevant Pages
|