Learn about Windows PowerShell
Summary: Use Windows PowerShell to show the minimum value and the maximum value of an [int16].
I need to use an [int16], but I am not sure if it is big enough to hold the number I want to use. How can I determine the minimum and the maximum value of an [int16]?
Use the static MinValue and MaxValue properties from the [int16], as shown here.
13:11 C:\> [int16]::MaxValue
32767
13:11 C:\> [int16]::MinValue
-32768
Note This technique also works for [int32], [int64], and [double].
How would one go about using this as a value in a commend? For example,
Get-Help Out-File -full | out-file .\oftest.txt -width [Int32]::MaxValue
will fail and I'm wondering if there is a way to reference it without creating a variable.
Thanks!
-Lee
@Lee you need to force evaluation of [int32] before you use it. To do this group it, as seen here:
get-help Out-File | Out-File c:\fso\outfile.txt -Width ([int32]::maxvalue)
PowerShell evaluates stuff in a pair of parentheses before it does the things outside the parentheses.
@Ed
Thank you! I've been googling like mad to figure that out and kept coming up blank.
@Lee you are welcome. Glad to help.
Works also for DateTime:
[DateTime]::MaxValue
[DateTime]::MinValue
@Henk very cool ... I have never done that before. It is a cool trick. Thanks for sharing.