---
title: "PowerShell Data Types & Type Accelerators: A Tutorial"
description: "Learn all about PowerShell data types and enhance your coding skills with type accelerators in this comprehensive tutorial."
canonical: "https://adamtheautomator.com/powershell-data-types/"
---

# PowerShell Data Types & Type Accelerators: A Tutorial

> Learn all about PowerShell data types and enhance your coding skills with type accelerators in this comprehensive tutorial.

Source: https://adamtheautomator.com/powershell-data-types/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![PowerShell Data Types & Type Accelerators: A Tutorial](https://adamtheautomator.com/wp-content/uploads/2020/08/Add-a-subheading.png)

# PowerShell Data Types & Type Accelerators: A Tutorial

[![](https://secure.gravatar.com/avatar/f08b754bc0dce1c76685f6afa93185ecfb6f861fd14f993286e06bba69eaeb8b?s=192&d=mm&r=g)Adam Listek](https://adamtheautomator.com/author/alistek/)26 August 20206 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[PowerShell](/tag/powershell/)

Table of Contents

*   [Type Accelerator Examples](#h-type-accelerator-examples)
*   [Discover PowerShell Data Types by Getting Type Accelerators](#h-discover-powershell-data-types-by-getting-type-accelerators)
*   [PowerShell Data Types Accelerators](#h-powershell-data-types-accelerators)
*   [URI](#h-uri)
*   [WMI, WMISearcher, WMIClass](#h-wmi-wmisearcher-wmiclass)
*   [XML](#h-xml)
*   [RegEx](#h-regex)
*   [DateTime](#h-datetime)
*   [TimeSpan](#h-timespan)
*   [IPAddress](#h-ipaddress)
*   [PSCredential](#h-pscredential)
*   [Conclusion](#h-conclusion)

Like many other languages, PowerShell uses objects for just about everything. PowerShell has data types to “categorize” types of objects with different schemas of properties and methods.

Once you wrap your head around PowerShell data types, you’ll soon see the time-saving ability of a concept called PowerShell type _accelerators_. Accelerators are methods to speed up assigning data types in PowerShell.

In this article, you’re going to learn about various object data types and also how to use accelerators to make it easier to work with them.

## Type Accelerator Examples

Even if you have not heard of accelerators before, you most likely have used them while coding. Using PowerShell to get types you will find, `[Array]`, `[Bool]`, or `[String]` are all type accelerators. What these class accelerators offer is quick access to the longer .NET definitions.

*   `[Array]` → `[System.Array]`
*   `[CmdletBinding]` → `[System.Management.Automation.CmdletBindingAttribute]`

How do we find out what our options are for using accelerators within PowerShell? Read on to learn all about type accelerators!

## Discover PowerShell Data Types by Getting Type Accelerators

PowerShell offers a one-line command that will return every type of accelerator known to PowerShell. For example, the available type accelerators from a PowerShell 7 environment are below.

```powershell
[PSObject].Assembly.GetType("System.Management.Automation.TypeAccelerators")::Get
```

```powershell
Key                          Value
---                          -----
Alias                        System.Management.Automation.AliasAttribute
AllowEmptyCollection         System.Management.Automation.AllowEmptyCollectionAttribute
AllowEmptyString             System.Management.Automation.AllowEmptyStringAttribute
AllowNull                    System.Management.Automation.AllowNullAttribute
ArgumentCompleter            System.Management.Automation.ArgumentCompleterAttribute
ArgumentCompletions          System.Management.Automation.ArgumentCompletionsAttribute
<SNIP>
```

Understanding how to use each accelerator is a different task altogether. To do so, you need to understand the constructors of a given accelerator. Using the GetConstructors method, we can discover the necessary parameters for a constructor.

First, we retrieve the `URI` accelerator to learn that there are six different types. The output may not always be clear about which value to use—if so, reading the Microsoft reference documents often clarifies how to use the class.

```powershell
( [Type]"URI" ).GetConstructors() | ForEach-Object {
	( $_.GetParameters() | ForEach-Object { $_.ToString() } ) -Join ", "
}
```

![Enumerating constructor parameters](https://adamtheautomator.com/wp-content/uploads/2020/08/Untitled-56-2.png)

Enumerating constructor parameters

## PowerShell Data Types Accelerators

Armed with the ability to find PowerShell data types accelerators and what constructors they may use, let’s dive into using the most common ones!

### [URI](https://docs.microsoft.com/en-us/dotnet/api/system.uri.-ctor?view=netcore-1.1)

URL’s (Uniform Resource Locators) and URI’s (Uniform Resource Identifiers) can be difficult to manipulate. Many times, the only recourse is to use string manipulation to extract the values that you need. .NET offers the `URI` type accelerator for these occasions.

The below example demonstrates passing a simple URL to the `URI` accelerator. The output is the component segments of the URI and makes manipulation much quicker.

```powershell
[URI]"https://google.com/"
```

![The schema for the URI type](https://adamtheautomator.com/wp-content/uploads/2020/08/Untitled-57-2.png)

The schema for the URI type

Once you have a URI object, there are simple methods available for further use as seen by the `Get-Member` output below.

```powershell
$URI = [URI]"https://google.com/"
$URI | Get-Member -Type Method
```

![Methods on URI type](https://adamtheautomator.com/wp-content/uploads/2020/08/Untitled-58-2.png)

Methods on URI type

### [WMI, WMISearcher, WMIClass](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_wmi_cmdlets?view=powershell-5.1#wmi-type-accelerators)

Familiar to many long-time PowerShell administrators is [WMI or Windows Management Instrumentation](https://adamtheautomator.com/powershell-wmi/). Many Windows settings exist within the WMI framework. So what can we do with the `WMI`, `WMISearcher`, and `WMIClass` accelerators?

*   `WMIClass` – Access the static properties and methods of a class.
*   `WMISearcher` – Create a search for WMI objects.
*   `WMI` – Retrieve a single instance of a class.

Demonstrated below is code using all three methods to create the `notepad.exe` process, locate that process, and then retrieve further process details.

```powershell
# Create notepad.exe Process
$ProcessManager = [WMICLASS]"root\cimv2:WIn32_Process"
$ProcessManager.Create("notepad.exe")

# Locate the notepad.exe process
$Search = [WmiSearcher]'SELECT * FROM Win32_Process'
$Processes = $Search.Get()
$Process = $Processes | Where-Object Name -Match "Notepad"

# Use WMI accelerator to retrieve the notepad.exe process
$WMIProcess = [WMI]("\.\root\cimv2:Win32_Process.Handle='{0}'" -F $Process.ProcessId)
```

### [XML](https://docs.microsoft.com/en-us/dotnet/api/system.xml.xmldocument?view=netcore-3.1)

Working with XML documents is a challenge. XML offers a flexible but verbose format. Attempting to parse through a long and complex document is difficult in any language. PowerShell makes this much easier using PowerShell data type accelerator `XML`. Consume an XML document, either from a string or from a file using [`Get-Content`](https://adamtheautomator.com/powershell-get-content/ "Get-Content").

```powershell
$XML = [XML]"<note>
	<to>Joe</to>
	<from>Ashley</from>
	<heading>Reminder</heading>
	<body>Don't forget Bob's birthday this weekend!</body>
</note>"

$XML.Note.Body
```

![XML example](https://adamtheautomator.com/wp-content/uploads/2020/08/Untitled-59-2.png)

XML example

You can see how it is easy to navigate through the nodes to find a specific value. For example, let’s say we don’t want the `heading` child node. XPath searches are easy to perform by using the `SelectNodes` method. Using the `SelectSingleNode` to target a single node, remove the node using the `RemoveChild` method.

```powershell
$XPath = '/note'
$Nodes = $XML.SelectNodes($XPath )
$Nodes | ForEach-Object {
  $Node = $_.SelectSingleNode('heading')
  $_.RemoveChild($Node) | Out-Null
}
```

![Removing XML nodes](https://adamtheautomator.com/wp-content/uploads/2020/08/Untitled-60-2.png)

Removing XML nodes

### [RegEx](https://docs.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex?view=netcore-3.1)

Regular Expressions make complex searches within text content easier. Constructing these queries is a challenge in and of itself. Once you have crafted the perfect query, you can use the PowerShell `RegEx` accelerator to perform a fast match on text content.

Although not technically a PowerShell data type, the `regex` type accelerator can still cut down tremendously on performing regex matches.

Below is a simple `RegEx` matching method. Craft a simple regular expression and call the `Match` method on a text string to perform a search.

```powershell
([RegEx]'\d{8}').Match('This will find the first 8 values, like 12345678').Value
```

![Matching strings with regex](https://adamtheautomator.com/wp-content/uploads/2020/08/Untitled-61-2.png)

Matching strings with regex

### [DateTime](https://docs.microsoft.com/en-us/dotnet/api/system.datetime?view=netcore-3.1)

Common to PowerShell is needing to work with dates in scripts. There are many ways to manipulate date and time. An easy way, with many useful methods, is by using the PowerShell data type `[DateTime]` accelerator. Some of the more useful techniques are:

*   Parsing a Date Time String
*   Formatting a Date Time
*   Date Time Arithmetic Operations

**Parsing a Date Time String**

Given a known date format (i.e., is not a custom format), the `DateTime` accelerator will return a valid `System.DateTime` object, which is the the same object type when using the `Get-Date` function.

```powershell
[DateTime]::Parse('2020-08-10')
```

![Converting strings to datetime objects](https://adamtheautomator.com/wp-content/uploads/2020/08/Untitled-62-2.png)

Converting strings to datetime objects

**Formatting a Date Time**

Data files often need a date-time string in a unique format. For example, let’s take the same date that we previously created and call the `ToString` method. To this method, we will pass the custom date format, `MM_dd_yyyy-hh:mm:ss`. Note that this is not a typical format, but using the `ToString` method, we will properly output the date in this format.

```powershell
([DateTime]::Parse('2020-08-10')).ToString('MM_dd_yyyy-hh:mm:ss')
```

![Converting strings and datetime objects](https://adamtheautomator.com/wp-content/uploads/2020/08/Untitled-63-2.png)

Converting strings and datetime objects

**Date Time Arithmetic Operations**

Adding and subtracting time from an existing `datetime` object is crucial. Instead of using complicated workarounds, leverage the `DateTime` class to perform these operations.

```powershell
([DateTime]::Parse('2020-08-10')).AddDays(5)
(([DateTime]::Parse('2020-08-10')).AddDays(5)).AddMonths(-2)
```

![Date arithmetic](https://adamtheautomator.com/wp-content/uploads/2020/08/Untitled-64-2.png)

Date arithmetic

With `5` days added, we also need to remove two months. Despite using the `AddMonths` method, passing a negative value subtracts the time. Chaining operations, using parentheses, we end up at the desired result.

### [TimeSpan](https://docs.microsoft.com/en-us/dotnet/api/system.timespan?view=netcore-3.1)

Much like the `DateTime` class, the `TimeSpan` class makes working with time ranges easy. Unlike `DateTime`, extra mathematical operations such as division and multiplication, are available.

**Creating a Time Span Object**

There are several ways that you can construct a timespan value. In our example, we are using the _Hours, Minutes, Seconds_ constructor. Other possible constructors are shown below.

*   Ticks
*   Hours, Minutes, Seconds
*   Days, Hours, Minutes, Seconds
*   Days, Hours, Minutes, Seconds, Milliseconds

```powershell
$TimeSpan = [TimeSpan]::New(1,0,0)
$TimeSpan
```

![Create timespans](https://adamtheautomator.com/wp-content/uploads/2020/08/Untitled-65-2.png)

Create timespans

**Multiplication and Division on a TimeSpan**

Let’s say you have defined a given time span, but you want to find out what three times that range would be. It is simple to do using the `Multiply` method.

```powershell
$TimeSpan.Multiply(3)
```

![Timespan ranges](https://adamtheautomator.com/wp-content/uploads/2020/08/Untitled-66-1.png)

Timespan ranges

What about division, though? How would we split a given time interval into fourths? We can use the `Divide` method to find the quarter values of time span.

```powershell
$TimeSpan.Divide(4)
```

![Timespan ranges again](https://adamtheautomator.com/wp-content/uploads/2020/08/Untitled-67-2.png)

Timespan ranges again

### [IPAddress](https://docs.microsoft.com/en-us/dotnet/api/system.net.ipaddress?view=netcore-3.1)

Navigating IP address management is a chore, as is validation. The `IPAddress` accelerator offers the ability to validate IPv4 and IPv6 addresses.

```powershell
[IPAddress]"10.0.0.1"
```

![The IPAddress type accelerator](https://adamtheautomator.com/wp-content/uploads/2020/08/Untitled-68-2.png)

The IPAddress type accelerator

As you can see, this is a valid IP address, but what if we had a value that we weren’t sure was a correct address? Passing a malformed or out of range address will result in an error informing of the incorrect value.

```powershell
[IPAddress]"258.0.0.1"
```

![Unable to convert to type](https://adamtheautomator.com/wp-content/uploads/2020/08/Untitled-69-2.png)

Unable to convert to type

### [PSCredential](https://docs.microsoft.com/en-us/dotnet/api/system.management.automation.pscredential?view=powershellsdk-7.0.0)

[Securing credentials](https://adamtheautomator.com/powershell-get-credential/) are critical to interacting with web services, remote systems, or third-party applications. The `PSCredential` class encrypts a password into an object. Passing this object into functions and cmdlets makes authentication easy.

In the example below, we are creating a `PSCredential` object used to store our secure values. Note that the password value requires a secure string.

```powershell
[PSCredential]::New("username", ("password" | ConvertTo-SecureString -AsPlainText -Force))
```

![Creating a new PSCredential](https://adamtheautomator.com/wp-content/uploads/2020/08/Untitled-70-2.png)

Creating a new PSCredential

Although we see the username value outputted here, we do not see the password value. How do we retrieve that?

```powershell
$Credential = [PSCredential]::New("username", ("password" | ConvertTo-SecureString -AsPlainText -Force))
$Credential | Format-List
```

![UserName and Password property on PSCredential](https://adamtheautomator.com/wp-content/uploads/2020/08/Untitled-71-2.png)

UserName and Password property on PSCredential

The simplest way to retrieve the password for this object is to use the `GetNetworkCredential` method. Next we will return the `password` property.

```powershell
$credential.GetNetworkCredential().Password
```

![Finding the password on a PSCredential object](https://adamtheautomator.com/wp-content/uploads/2020/08/Untitled-72-1.png)

Finding the password on a PSCredential object

## Conclusion

PowerShell Data Types accelerators make complex operations easy in PowerShell. There are many accelerators, but with these tips, you should be able to use Powershell to get the many types and discover new uses. There are often unique ways to use accelerators. Learning these differences will increase your productivity drastically!

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-data-types%2F&text=PowerShell%20Data%20Types%20%26%20Type%20Accelerators%3A%20A%20Tutorial)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-data-types%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-data-types%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2026/06/26995-troubleshoot-dns-issues-powershell-codex.webp)

### [Troubleshoot DNS Issues with PowerShell](/troubleshoot-dns-issues-powershell/)

Troubleshoot DNS issues with PowerShell by testing name resolution, DNS client settings, cache entries, and network connectivity in a repeatable workflow.

![](https://adamtheautomator.com/wp-content/uploads/2025/10/image_2025-10-24_095322075.png)

### [Migrating from PowerShell 6 to 7.5: Breaking Changes/New Features](/migrating-powershell-6-to-7-5/)

Migrate from PowerShell Core 6 to 7.5: breaking changes, features, and testing tips.

![](https://adamtheautomator.com/wp-content/uploads/2025/06/featured-image-6.png)

### [How to Add Timeouts to Pester Tests with PowerShell Runspaces](/pester-test-timeout-runspaces/)

Prevent Pester tests from hanging indefinitely using PowerShell runspaces. Learn to handle variable scoping, module loading, TestDrive access, and stream capture challenges with timeout protection.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
