Re: [MSH] Script parameter without a value



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: CRL Distribution Points
    ... This posting is provided "AS IS" with no warranties, and confers no rights. ... "Param" wrote in message ... > I have a certificate containg CRL Distribution Point URL as ldap. ...
    (microsoft.public.platformsdk.security)
  • Re: Authority Information Access
    ... This posting is provided "AS IS" with no warranties, and confers no rights. ... "Param" wrote in message ... > I have a certificate with Authority Information Access as a field ...
    (microsoft.public.platformsdk.security)
  • Re: Install Windows Patch via GPO
    ... This posting is provided "AS IS" with no warranties, and confers no rights. ...
    (microsoft.public.windows.group_policy)
  • Re: Trust windows 2k to windows 2k3
    ... This posting is provided "AS-IS" with no warranties or guarantees and ... confers no rights. ... only reply to Newsgroups ...
    (microsoft.public.windows.server.active_directory)
  • Re: Trust windows 2k to windows 2k3
    ... This posting is provided "AS-IS" with no warranties or guarantees and confers no rights. ... only reply to Newsgroups ...
    (microsoft.public.windows.server.active_directory)