Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What Data Types does PowerShell have?

Tags:

powershell

I searched on Stack Overflow and Google but couldn't find an answer to my question: Which data types (e.g. string, XML, regex, int etc.) does PowerShell have? There seems to be no list on Microsoft TechNet and I found no way to simply list them all.

like image 436
Velocet Avatar asked Sep 18 '16 20:09

Velocet


1 Answers

As already hinted by PetSerAl, the type system in PowerShell is a direct extension of the .NET CTS - any .NET type loaded into the AppDomain currently hosting your PowerShell environment can be used.

In .NET, types (classes, structs, enums and builtin value types) are compiled into assemblies (usually in the form of a .dll file).

If you want an exhaustive list of those, you can simply enumerate all assemblies currently loaded into memory, then enumerate all the types in said assemblies:

[AppDomain]::CurrentDomain.GetAssemblies() |Foreach-Object {
    $_.GetExportedTypes()
}

If you just want a list of all the Type Accelerators (the shortname aliases like [regex],[wmi], [adsi] etc.), you can use the following trick:

$AcceleratorType = [psobject].Assembly.GetType("System.Management.Automation.TypeAccelerators")
$AcceleratorType::Get
like image 171
Mathias R. Jessen Avatar answered Oct 09 '22 18:10

Mathias R. Jessen