How to get the variable data type in PowerShell? (2024)

Table of Contents
Example Output FAQs

There are different data types exist for the variable like Byte, Int32, Float, String, etc. To get the variable type, we need to use the GetType() method.

Example

$x = 10 $x.GetType()

Output

IsPublic IsSerial Name BaseType-------- -------- ---- --------True True Int32 System.ValueType

To get only the variable datatype use Name property.

$x.GetType().Name
Int32

Updated on: 20-Mar-2020

60K+ Views

Related Articles

Kickstart Your Career

Get certified by completing the course

Get Started

How to get the variable data type in PowerShell? (31)

Advertisem*nts

How to get the variable data type in PowerShell? (2024)

FAQs

How to find the datatype of a variable in PowerShell? ›

To determine the data type of a PowerShell variable using command-line operations, you can use the GetType() method on the variable. This method returns the type information of the variable.

How do you get the variable value in PowerShell? ›

The default value of all variables is $null . To get a list of all the variables in your PowerShell session, type Get-Variable . The variable names are displayed without the preceding dollar ( $ ) sign that is used to reference variables.

How do you get the properties of a variable in PowerShell? ›

The most common way to get the values of the properties of an object is to use the member access operator ( . ). Type a reference to the object, such as a variable that contains the object, or a command that gets the object. Then, type the operator ( . ) followed by the property name.

What does $_ mean in PowerShell? ›

PowerShell includes the $PSItem variable and its alias, $_ , as automatic variables in scriptblocks that process the current object, such as in the pipeline.

How do you check the data type of a variable? ›

To check the type of any variable data type, we can use the type() function. It will return the type of the mentioned variable data type. Float data type is used to represent decimal point values.

How do you check the type of a variable? ›

To get the type of a variable in Python, you can use the built-in type() function. In Python, everything is an object. So, when you use the type() function to print the type of the value stored in a variable to the console, it returns the class type of the object.

How do you check if a variable contains a string in PowerShell? ›

The Contains method in PowerShell can be used to check if a specified string or character exists within a string, and the PowerShell operator Contains allows you to check if a collection of objects, such as an array, contains a specific value.

How to find datatype of a variable in js? ›

You can use the typeof operator to find the data type of a JavaScript variable.

How do I find the data type of a variable in SQL? ›

In SQL Runner, you can use these queries:
  1. MySQL: SELECT. COLUMN_NAME, DATA_TYPE. FROM. INFORMATION_SCHEMA.COLUMNS. WHERE. ...
  2. PostgreSQL: pg_typeof(col_name)
  3. Redshift: SELECT "column", type. FROM PG_TABLE_DEF. WHERE tablename = 'table_name' AND "column" = 'column_name' BQ Legacy and Standard don't support these types of queries.
Jul 5, 2021

What is @{} in PowerShell? ›

@{} in PowerShell defines a hashtable, a data structure for mapping unique keys to values (in other languages this data structure is called "dictionary" or "associative array").

Top Articles
Latest Posts
Article information

Author: Clemencia Bogisich Ret

Last Updated:

Views: 6494

Rating: 5 / 5 (80 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Clemencia Bogisich Ret

Birthday: 2001-07-17

Address: Suite 794 53887 Geri Spring, West Cristentown, KY 54855

Phone: +5934435460663

Job: Central Hospitality Director

Hobby: Yoga, Electronics, Rafting, Lockpicking, Inline skating, Puzzles, scrapbook

Introduction: My name is Clemencia Bogisich Ret, I am a super, outstanding, graceful, friendly, vast, comfortable, agreeable person who loves writing and wants to share my knowledge and understanding with you.