Data Types#

Basic Data Types#

  • [string] — a string used to represent text.
  • [char] — a 16-bit character in Unicode format, used to represent individual characters.
  • [byte] — an 8-bit numeric type, typically used for handling binary data.
  • [int] — a 32-bit integer, a common type for working with integer values.
  • [long] — a 64-bit integer, used for large integer values.
  • [bool] — a boolean type that accepts True or False values, used for logical operations.
  • [decimal] — a 128-bit floating-point number, optimal for financial calculations with high precision.
  • [single] — a 32-bit floating-point number.
  • [double] — a 64-bit floating-point number, well-suited for scientific and engineering calculations.
  • [DateTime] — a data type for storing date and time.
  • [xml] — an object for working with XML data.
  • [array] [string[]] — an array, can be created with examples: @(1,2,3) or simply (1,2,3). It is important to remember that (1) is not an array, but a scalar value. Arrays allow storing sets of elements of the same or different data types. More information can be found in the official documentation on arrays:
everything about arrayslearn.microsoft.com
  • [hashtable] — a hash table or dictionary with keys and values, for example: @{1=11; 2=12; 3=14}. It is convenient for associative data storage. More about hash tables can be read in the reference materials:
everything about hashtablelearn.microsoft.com

Type Conversion#

  • Converting a string value to a date:
powershell"5/7/07" -as [DateTime]
  • Alternative conversion using type casting:
powershell[datetime]"5/7/07"
  • Using a method from the Convert class:
powershell[Convert]::ToDateTime("5/7/07")
  • Example of converting a numeric expression to a string:
powershell(1 + 1 * 2).ToString()