Groups > Microsoft > Windows PowerShell > Re: Confusing prompt for a [bool] value (V2 CTP)




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

Confusing prompt for a [bool] value (V2 CTP)
Thu, 10 Apr 2008 10:36:52 +010
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(;;) 
# 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
 
Post Reply
Re: Confusing prompt for a [bool] value (V2 CTP)
Fri, 11 Apr 2008 11:28:28 -030
> 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:
Post Reply
Re: Confusing prompt for a [bool] value (V2 CTP)
Fri, 11 Apr 2008 13:36:46 -030
> 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.

Post Reply
Re: Confusing prompt for a [bool] value (V2 CTP)
Fri, 11 Apr 2008 16:38:25 +010
> 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

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
 
Post Reply
Re: Confusing prompt for a [bool] value (V2 CTP)
Mon, 14 Apr 2008 16:07:31 -030
Marco Shaw [MVP] wrote:
> 
>> 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:
Post Reply
about | contact