Re: [MSH] Script parameter without a value



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: Finetuning: Remote Shutdown with WMI, some errors occur.
    ... Allows shutdown, poweroff, or reboot of multiple remote systems. ... - generic unhandled script compile or runtime error; ... "Specify 1 and only one shutdown action" ... Dim erNumber, erDesc ...
    (microsoft.public.windows.server.scripting)
  • Re: use text file for strComputer in VBS script
    ... ' Read each line of the file and set strComputer. ... > 'are not bothered by potential operational errors with the script. ... > ' Specify the text file of computerNames. ...
    (microsoft.public.windows.server.scripting)
  • Re: use text file for strComputer in VBS script
    ... ' Read each line of the file and set strComputer. ... > 'are not bothered by potential operational errors with the script. ... > ' Specify the text file of computerNames. ...
    (microsoft.public.scripting.wsh)
  • Re: use text file for strComputer in VBS script
    ... ' Read each line of the file and set strComputer. ... > 'are not bothered by potential operational errors with the script. ... > ' Specify the text file of computerNames. ...
    (microsoft.public.win32.programmer.wmi)
  • Re: use text file for strComputer in VBS script
    ... ' Read each line of the file and set strComputer. ... > 'are not bothered by potential operational errors with the script. ... > ' Specify the text file of computerNames. ...
    (microsoft.public.scripting.vbscript)

Loading