Re: [MSH] Script parameter without a value



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












.



Relevant Pages

  • Re: [msh]get-content of large files.
    ... Microsoft Corporation ... This posting is provided "AS IS" with no warranties, ... The log files are text files in ASCII format and use the W3C standard ...
    (microsoft.public.windows.server.scripting)
  • Re: Why disappear Database menu option?
    ... Mark Nelson ... Microsoft Corporation ... This posting is provided "AS IS" with no warranties, ...
    (microsoft.public.visio.general)
  • Re: line spacing
    ... Mark Nelson ... Microsoft Corporation ... This posting is provided "AS IS" with no warranties, ...
    (microsoft.public.visio.general)
  • Re: Fact Editor in Visio 2003 Pro
    ... Mark Nelson ... Microsoft Corporation ... This posting is provided "AS IS" with no warranties, ...
    (microsoft.public.visio)
  • Re: [MSH] Script parameter without a value
    ... param ... This posting is provided "AS IS" with no warranties, and confers no rights. ...
    (microsoft.public.windows.server.scripting)