An integer is a whole number with no fractional or decimal portion. In PowerShell, parameter help may label integer input as Int, Int32, or Int64. These labels tell you what kind of value a command expects. section 3.5.4
PowerShell can mistake user input for text. If a variable receives the string "100", multiplying it by 10 repeats the text instead of performing arithmetic. Declaring the variable with [int] forces integer conversion and makes the intended operation clear. section 16.6
Force numeric input
Use [int] before the variable when reading a number: [int]$number = Read-Host "Enter a number". Entering 100 produces a System.Int32 value, so $number * 10 returns 1000. Entering Hello raises a conversion error rather than silently storing unusable text. section 16.6
Use an integer as a command value
A variable can stand in for a numeric command argument. Assigning 13481 to $var and running Get-Process -Id $var retrieves the process with that identifier; Get-Member identifies the value as System.Int32. section 16.2
PS > [int]$number = Read-Host "Enter a number" #1 Enter a number: 100 PS > $number | Get-Member TypeName: System.Int32 #2 Name MemberType Definition ---- ---------- ---------- CompareTo Method int CompareTo(System.Object value), int CompareT... Equals Method bool Equals(System.Object obj), bool Equals(int ... GetHashCode Method int GetHashCode() GetType Method type GetType() GetTypeCode Method System.TypeCode GetTypeCode() ToString Method string ToString(), string ToString(string format... PS > $number = $number * 10 PS > $number 1000 #3
Inspect the complete typed-input example, including [int] declaration, System.Int32 output, multiplication, and the resulting value. section 16.6














