What is INT ?


I’m new to powershell and just watched the excellent “Getting Started with PowerShell 3.0 Jump Start” videos. Trying to get my head around things.

The command below, in the second line, after -as what is the [INT] ? What does that mean/do ?

Get-wmiobject win32_logicaldisk -filter “DeviceID=‘c:’” |
select @{n=‘FreeGb’;e={$_.freespace / 1gb -as [int]}}


[int] is a .NET type literal; in this case, it’s for the 32-bit signed Integer type ([int] is a shorcut for [System.Int32]). It can represent any whole number (no decimal points or fractions) between -2147483648 and 2147483647.

In this case, what that’s doing is taking the result of ($_.FreeSpace / 1GB), which will likely contain a large number of decimal places, and casting it to a whole number. Whether this rounds the number or just truncates the decimal portion depends on what language you’re using. In the case of PowerShell, it rounds the number (and uses banker’s rounding for x.5 values; they get rounded to the nearest even number, so 0.5 becomes 0 and 1.5 becomes 2.)