Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums

Go Back   Vista Forums > Vista technology newsgroups > PowerShell

Confusing prompt for a [bool] value (V2 CTP)

Reply
 
Thread Tools Display Modes
Old 04-10-2008   #1
Roman Kuzmin
Guest
 
Posts: n/a

Confusing prompt for a [bool] value (V2 CTP)

Run this (script cmdlet with a mandatory [bool] parameter), input various
values and watch the results (Ctrl-C to stop). Everything except an empty
string is converted into True.

# begin test
cmdlet Test-Me
{
param ( [Mandatory][bool]$Bool )
$CommandLineParameters
}
for(; { Test-Me }
# end test

Output (filtered):
Bool: 1
Bool True
Bool: 0
Bool True
Bool: True
Bool True
Bool: False
Bool True
Bool: $True
Bool True
Bool: $False
Bool True
Bool:
Bool False

The question:
Is this by design, a bug or am I missing something?

--
Thanks,
Roman Kuzmin

http://code.google.com/p/farnet/
PowerShell and .NET in FAR Manager


  Reply With Quote

Old 04-11-2008   #2
Marco Shaw [MVP]
Guest
 
Posts: n/a

Re: Confusing prompt for a [bool] value (V2 CTP)

Quote:

> The question:
> Is this by design, a bug or am I missing something?
>
I've never seen anyone try using [bool]. What are you trying to
accomplish exactly? I discussed this with Don Jones, and he indicated
perhaps you should be using [switch] if your goal is to determine
whether a parameter is set or not, instead of trying to do something like:
cmdlet -parameter true <--bool which you're trying
Just do
cmdlet -parameter <--[switch]

Marco

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
  Reply With Quote
Old 04-11-2008   #3
Roman Kuzmin
Guest
 
Posts: n/a

Re: Confusing prompt for a [bool] value (V2 CTP)

> I've never seen anyone try using [bool]. What are you trying to
Quote:

> accomplish exactly? I discussed this with Don Jones, and he indicated
> perhaps you should be using [switch] if your goal is to determine whether
> a parameter is set or not, instead of trying to do something like:
> cmdlet -parameter true <--bool which you're trying
Thank you very much, indeed, but I was not asking for a workaround. I was
looking for potential bugs hoping that it may help to make them found and
fixed.

I will hardly ever use [bool] parameter, but if this is a bug then its
origins may affect something else, much more serious, but not yet
discovered.

--
Thanks,
Roman Kuzmin

http://code.google.com/p/farnet/
PowerShell and .NET in FAR Manager


  Reply With Quote
Old 04-11-2008   #4
Marco Shaw [MVP]
Guest
 
Posts: n/a

Re: Confusing prompt for a [bool] value (V2 CTP)

Quote:

> Thank you very much, indeed, but I was not asking for a workaround. I
> was looking for potential bugs hoping that it may help to make them
> found and fixed.
>
> I will hardly ever use [bool] parameter, but if this is a bug then its
> origins may affect something else, much more serious, but not yet
> discovered.
True. It has brought up some interesting points in a private list I'm
on. I'm not going to share them right now though (and haven't asked
permission to do so either).

I may try it in C# (with a real cmdlet) just to see how it works that way.

Marco
  Reply With Quote
Old 04-14-2008   #5
Marco Shaw [MVP]
Guest
 
Posts: n/a

Re: Confusing prompt for a [bool] value (V2 CTP)

Marco Shaw [MVP] wrote:
Quote:

>
Quote:

>> Thank you very much, indeed, but I was not asking for a workaround. I
>> was looking for potential bugs hoping that it may help to make them
>> found and fixed.
>>
>> I will hardly ever use [bool] parameter, but if this is a bug then its
>> origins may affect something else, much more serious, but not yet
>> discovered.
>
> True. It has brought up some interesting points in a private list I'm
> on. I'm not going to share them right now though (and haven't asked
> permission to do so either).
>
> I may try it in C# (with a real cmdlet) just to see how it works that way.
>
> Marco
I don't have any updates. I've not gotten around to trying to figure
out how to write this in C# as a real cmdlet...

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
  Reply With Quote
 
Reply

Thread Tools
Display Modes









Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Vistax64.com 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48