[DBG]: PS C:\Windows\system32>>> echo [uint32]::maxvalue
[uint32]::maxvalue
and
[DBG]: PS C:\Windows\system32>>> $mv = [uint32]::maxvalue
[DBG]: PS C:\Windows\system32>>> echo $mv
4294967295
I am sure powershell has some perfectly good reason for doing this :-). Is there someway i can tell it not to do it. I am actually passing and int to a function and sometimes I want to pass maxvalue
I know I can do
$mv = [uint32]::maxvalue
MyFunc $mv
I am wondering if there is something like
MyFunc ([uint32]::maxvalue)
MyFunc `[uint32::maxvalue`
etc
The reason why is that the echo
command is interpreting the argument as a string
and not an arbitrary value. Hence in the first example it's printing out the argument literally vs. interpreting it as a value. In the second case though it's being interpreted as an expression and being assigned to a value.
You can reproduce this behavior by creating a function yourself that echos the output to the console.
function example {
param ([string]$arg)
Write-Output $arg
}
example [uint]
> [uint]
example 42
> 42
You can also force the echo
function to interpret it as a value by using ()
s to specify it's an expression
echo [uint32]::maxvalue
> [uint32]::maxvalue
echo ([uint32]::maxvalue)
> 4294967295
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With