First of all, you lack parentheses to call GetType. What you see is the MethodInfo describing the GetType method on [DayOfWeek]. To actually call GetType, you should do:

$a.GetType();
$b.GetType();

You should see that $a is a [DayOfWeek], and $b is a custom object generated by the Select-Object cmdlet to capture only the DayOfWeek property of a data object. Hence, it's an object with a DayOfWeek property only:

C:\> $b.DayOfWeek -eq $a
True
Answer from Cédric Rup on Stack Overflow
🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › scripting › lang-spec › chapter-04
Types - PowerShell | Microsoft Learn
In PowerShell, this type is System.Management.Automation.PSCustomObject. The cmdlets Import-Module and New-Object can generate an object of this type. The automatic variable $PSCmdlet is an object that represents the cmdlet or function being executed.
Discussions

Powershell and Types
Get-member will be your friend. The type is typically at the top of the output. It will also output methods and properties of the variable//output that is being referenced. More on reddit.com
🌐 r/PowerShell
32
11
August 28, 2024
powershell - How to explicitly declare type of a variable when creating that variable with New-Variable function? - Stack Overflow
I'm interested in what your use ... into powershell. ... "I could not figure out how to construct the Attributes from scratch" should work on that in the future, would be a useful thing to know 2018-08-18T22:27:46.74Z+00:00 ... This attribute class is defined internal sealed. The compiler is the primary creator of Attributes. For now, compiling the text [typename] $variableName via ... More on stackoverflow.com
🌐 stackoverflow.com
Variable naming
$Fish = [pscustomobject]@{Name = 'Bob'; Species = 'Carp'} Is better than $MyHashTable = [pscustomobject]@{Name = 'Bob'; Species = 'Carp'} #Store detail of fish Here's a more reputable source with lots of detail if you're interested in the conventions people have settled on- https://github.com/PoshCode/PowerShellPracticeAndStyle/blob/master/Style-Guide/Naming-Conventions.md More on reddit.com
🌐 r/PowerShell
22
16
November 14, 2023
Set-content how write $variable as it is and not as variable
Read this: about_Quoting_Rules . More on reddit.com
🌐 r/PowerShell
9
6
July 8, 2022
🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › module › microsoft.powershell.core › about › about_variables
about_Variables - PowerShell | Microsoft Learn
In PowerShell, variables are represented by text strings that begin with a dollar sign ($), such as $a, $process, or $my_var. Variable names aren't case-sensitive, and can include spaces and special characters. But, variable names that include special characters and spaces are difficult to use and should be avoided. For more information, see Variable names that include special characters. There are several different types of variables in PowerShell.
🌐
SharePoint Diary
sharepointdiary.com › sharepoint diary › powershell › how to get the variable type in powershell?
How to Get the Variable Type in PowerShell? - SharePoint Diary
September 22, 2025 - It wasn’t until I started checking the variable types that I figured out what was going wrong. PowerShell uses dynamic typing, meaning variables can hold values of any type without explicitly declaring the type.
🌐
Reddit
reddit.com › r/powershell › powershell and types
r/PowerShell on Reddit: Powershell and Types
August 28, 2024 -

Once upon a time I was a C/C++ programmer. I am trying to get my feet wet with PS to accomplish some maintenance tasks on my computer that might not justify either a command line or Windows app. The lack of typing in PS is really messing with my head. It seems as though variables can be created as any type and that "functions" in PS can return a wide variety of types.

How am I supposed to know what is in a variable if I cannot trace it back to its declaration and see a type?

Example question...

$filenames = Get-ChildItem -Path "D:\Brian's Stuff\Media\Data\Video\Santa Barbara\0001 - 0100\Santa Barbara 8493" -Filter *.mp4

So apparently this invocation of Get-ChildItem returns a collection. How do I know the collection type (is it an array? A linked list? An abstraction of a binary tree?) And what about the type of object being stored in the collection. How do I determine that without any variable typing? $filenames is a collection, but of what? And it all can change depending on what type of information I am asking Get-ChildItem for?

Maybe I need to find a strongly typed language. I don't get it. BTW I am literally 6 hours old with PS. Just started. Trying to learn only what I need to learn to get the job done. Don't intend to study the language out of intellectual curiousity.

Top answer
1 of 5
14
Get-member will be your friend. The type is typically at the top of the output. It will also output methods and properties of the variable//output that is being referenced.
2 of 5
12
So apparently this invocation of Get-ChildItem returns a collection. Get-ChildItem does not return a collection. It emits scalar (single) objects to the pipeline in a continuous stream. This applies to most cmdlets. If output is captured to a variable (like in your example), PowerShell will internally collect each emitted object. Upon completion, the resultant variable's value and type is dependent on the number of objects emitted. If no objects are emitted, the variable's value is AutomationNull, which represents nothing in PowerShell. It is not $null, which differs from "nothing". If one object is emitted, the variable's value is the object of whichever object type was emitted. If multiple objects are emitted, the variable's value is a collection of type [object[]] (an array), containing each object emitted. In your example, Get-ChildItem may emit [IO.FileInfo] and/or [IO.DirectoryInfo] instances or nothing depending on what type of item (if any) is found. You could limit the results to files only by specifying the -File parameter. Reflection can be performed with the GetType() method. $fileNames.GetType().FullName will give you the full type name, which you can lookup using the .NET API browser (providing the type is from Microsoft). Get-Member is another valuable tool to aid object exploration. $array = 1, 2, 3 $array | Get-Member # Get instance members of the array's elements $array | Get-Member -Static # Static members only Get-Member -InputObject $array # Instance members of the array itself Further reading: about_Objects about_Properties about_Methods Chapter 3 - Discovering objects, properties, and methods Viewing object structure
🌐
Wikiversity
en.wikiversity.org › wiki › PowerShell › Variables
PowerShell/Variables - Wikiversity
October 25, 2023 - Use variables to capture user input and use that input later in script output. ... PowerShell data types include integers, floating point values, strings, Booleans, and datetime values.[1] The GetType method returns the current data type of the given variable.[2]
🌐
SS64
ss64.com › ps › syntax-datatypes.html
PowerShell Data Types
Variables and Operators - Create, add, subtract, divide. Enum - Create and use PowerShell enums. [math]::Round - Round a number to any given number of decimal places. DateTime formats Format-Hex - Display a file or other input as hex.
Find elsewhere
🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › scripting › lang-spec › chapter-05
Variables - PowerShell | Microsoft Learn
A writable location may be a variable ... of variables: static variables, instance variables, array elements, Hashtable key/value pairs, parameters, ordinary variables, and variables on provider drives....
🌐
4sysops
4sysops.com › home › blog › articles › the powershell variable – naming, value, data type
The PowerShell variable – Naming, value, data type
July 28, 2023 - However, if no reasonable way exists to automatically convert the data type, and the data type doesn’t fit with the operation, PowerShell will throw an error. For instance, the lines below will produce the error message “Cannot convert value ‘b’ to type ‘System.Int32.’” ... It is important to note that automatic conversion does not change the variable’s data type. Even though the value of the variable $b in the example has been used as an integer in the calculation, its data type is still String.
🌐
AttuneOps
attuneops.io › attune-hub › powershell-basics-variables-and-data-types
PowerShell Basics: Variables and Data Types - AttuneOps
October 24, 2025 - Automatic variables: These are variables that are created by PowerShell. Their values change as required to maintain their accuracy. Users can't change the value of these variables.
🌐
SharePoint Diary
sharepointdiary.com › sharepoint diary › powershell › powershell variable data types: all you need to know
PowerShell Variable Data Types: All You Need to Know
September 22, 2025 - A variable in PowerShell is denoted by a dollar sign ($) followed by the variable name, and it is not case-sensitive. For instance, you might use $number to store an integer or $message to store a string.
🌐
ShellGeek
shellgeek.com › home › powershell tips › gettype – get variable data type in powershell
GetType - Get Variable Data Type in PowerShell - ShellGeek
April 14, 2024 - In the above PowerShell script example, the $Test variable contains numeric data separated by, (comma). To get data type of variable $Test, use GetType().
🌐
MSSQLTips
mssqltips.com › home › powershell variable examples for data types, scope, naming, assignment
PowerShell Variable Examples for Data Types, Scope, Naming, Assignment
February 10, 2022 - In this case, PowerShell will stick to the String data type (in double quotes) from this point forward, during the whole lifecycle of the script, unless another explicit data type assignation takes place at some point within the script (it will basically forget that the variable was initially an integer).
🌐
Codecademy
codecademy.com › docs › powershell › variables
PowerShell | Variables | Codecademy
June 8, 2023 - Variables names are not case-sensitive and can include spaces and special characters. The convention is to use only alphanumeric characters and the underscore _ character. PowerShell dynamically assigns a type to a variable depending on the value assigned to it.
🌐
PsCustom Object
pscustomobject.github.io › powershell › coding habits › powershell best practice › PowerShell-Strongly-Typed-Variables
PowerShell Strongly Typed Variables - PsCustom Object - Hitchikers GUID(e) to Automation
February 2, 2019 - I pride myself on hand-crafting every line of code—no AI shortcuts here! Join me in my journey, where clean, readable code is the norm, and automation is an art form. ... PowerShell is dynamically implicit typed, this is a fact. What does that mean? Unlike other languages, C# or even C/C++, changing a variable’s type won’t generate an error.
🌐
LazyAdmin
lazyadmin.nl › home › how to use powershell variables
How to use PowerShell Variables — LazyAdmin
January 18, 2024 - Preference variables – These variables are also created by PowerShell, but the difference is that you can change these variables to customize the behavior of PowerShell. A good example is the variable $ErrorActionPreference that allows you to set what PowerShell should do when it runs into an error. You can find all the preference variables here. As already briefly covered in the beginning, creating a variable is pretty straightforward. For a simple, loose typed, variable, you only need to specify the variable name.
🌐
TutorialsPoint
tutorialspoint.com › article › how-to-get-the-variable-data-type-in-powershell
How to get the variable data type in PowerShell?
March 20, 2020 - PowerShell Microsoft Technologies Software & Coding · 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.
🌐
PowerShell Test-Path
powershellfaqs.com › powershell-get-variable-type
How to Get the Type of a Variable in PowerShell?
September 6, 2024 - In this example, we assign the string value “New York” to the variable $usaCity. By appending .GetType().Name to the variable, PowerShell returns the type of the variable, which is “String” in this case.
🌐
Practical PowerShell
practicalpowershell.com › home › powershell tips › what type? gettype()
What Type? GetType() - Practical PowerShell
June 7, 2020 - There are multiple types of variables. Variables can contain numbers, strings and more. Sometimes this can be key to how we handle the data on the variable or how we can display or search for information in the variable. First we will take a look at Get-Date. Get-Date pulls your current date and time information from your computer. We can store this information in a variable and then see how that data is being stored/interpreted by PowerShell: Notice that the type is ‘DateTime’ which is logical considering what could pulled from Get-Date.
Top answer
1 of 6
8

This is pretty much impossible to do now in PowerShell so I've opened an issue You should be able to set the type conversion attribute on a variable with New-Variable to address this.

2 of 6
4

The difference between a variable with and without a type specifier [int32] is in the variable attributes:

[int32] $var1 = 32
$var2 = 'a'

Get-Variable -Name 'var1' | fl *
Get-Variable -Name 'var2' | fl *

yields:

Name        : var1
Description :
Value       : 32
Visibility  : Public
Module      :
ModuleName  :
Options     : None
Attributes  : {System.Management.Automation.ArgumentTypeConverterAttribute}

Name        : var2
Description :
Value       : a
Visibility  : Public
Module      :
ModuleName  :
Options     : None
Attributes  : {}

New-Variable doesn't support setting these attributes, so it isn't possible to make the equivalent of [int32] $myVarname using New-Variable

It is possible to use the .net [psvariable]::new() constructor to create a variable with these attributes. I could not figure out how to construct the Attributes from scratch to make the equivalent of [int32], but was able to successfully copy attributes from another variable during construction:

[int32] $int32ConstrainedVar1 = 32
$var1Attributes = (Get-Variable -Name 'int32ConstrainedVar1').Attributes
$newConstrainedVar = [psvariable]::new('int32ConstrainedVar2', 33, 'None', $var1Attributes)

After this, trying to assign something that cannot be converted to [int32] fails, as expected:

$newConstrainedVar.Value = 'asdf'

yields:

Exception setting "Value": "Cannot convert value "asdf" to type "System.Int32". Error: "Input string was not in a correct format.""
At line:1 char:1
+ $newConstrainedVar.Value = 'asdf'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [], SetValueInvocationException
+ FullyQualifiedErrorId : ExceptionWhenSetting

Sorry for the sketchy details; this is a level of powershell internals that's new to me.

I'm interested in what your use case is; The only reason I can imagine you'd want to work at this low a level with powershell is if you're writing a runtime that translates from another language into powershell.