A data type tells PowerShell what kind of value a variable contains and which operations apply. Input from Read-Host arrives as text, so multiplying "100" by 10 repeats the string instead of calculating 1,000. Declaring [int] before a variable makes PowerShell convert the input and reject values that are not valid integers. section 16.6
PS > $number = Read-Host "Enter a number" Enter a number: 100 PS > $number = $number * 10 PS > $number 100100100100100100100100100100
Run the command to see how treating input as a string produces repeated text rather than numeric multiplication. section 16.6
Use type declarations and operators to control values:
- [int], [single], and [double] represent numbers; [string] represents characters; [char] represents one character; and [xml] validates and parses XML content. section 16.6
- Inspect a value with Get-Member to confirm its runtime type and available members. section 16.6
- Use -as to attempt conversion, and use -is to test whether an object already has a particular type. section 26.2.1
- Apply conversion inside formatted output, such as turning process memory from megabytes with decimals into whole numbers. section 11.6
Typed input
Declare [int]$number before Read-Host, then inspect it with Get-Member and multiply it. Entering 100 produces 1000; entering Hello raises a conversion error. A typed variable continues enforcing its type until explicitly retyped. section 16.6
















