PowerShell: Using PS Accelerators and Types + Get full list of PS Accelerators!

 

Have you ever heard about PowerShell Accelerators?

It is what makes it easy to handle stuff like XML files, WMI Objects or Active Directory Objects.

We use it for pre-defining variable and calculations types too.

 

for example we can read a XML file using [xml] and get-content

PS C:\> $xml = [xml] (Get-Content myXMLFile.xml)

by using this method we are able to parse the XML into real PS objects, and therefore we can acess the parts by using the dot net way.

PS C:\> $xml.Config.ServerName

 

This will read the ServerName Tag inside the Config tag.

Problem is that there is a lot of these, and no official complete list.

One of the reasons is that, new accelerators might become available, when you import modules.

But by using these few lines of code you will get the complete list of available accelerators:

On my windows 7 PC I have the following list (no extra modules is loaded)

Key                                     Value

—                                     —–

int                                     System.Int32

long                                    System.Int64

string                                  System.String

char                                    System.Char

bool                                    System.Boolean

byte                                    System.Byte

double                                  System.Double

decimal                                 System.Decimal

float                                   System.Single

single                                  System.Single

regex                                   System.Text.RegularExpressions.Regex

array                                   System.Array

xml                                     System.Xml.XmlDocument

scriptblock                             System.Management.Automation.ScriptB…

switch                                  System.Management.Automation.SwitchP…

hashtable                               System.Collections.Hashtable

type                                    System.Type

ref                                     System.Management.Automation.PSRefer…

psobject                                System.Management.Automation.PSObject

pscustomobject                          System.Management.Automation.PSObject

psmoduleinfo                            System.Management.Automation.PSModul…

powershell                              System.Management.Automation.PowerShell

runspacefactory                         System.Management.Automation.Runspac…

runspace                                System.Management.Automation.Runspac…

ipaddress                               System.Net.IPAddress

wmi                                     System.Management.ManagementObject

wmisearcher                             System.Management.ManagementObjectSe…

wmiclass                                System.Management.ManagementClass

adsi                                    System.DirectoryServices.DirectoryEntry

adsisearcher                            System.DirectoryServices.DirectorySe…

psprimitivedictionary                   System.Management.Automation.PSPrimi…

accelerators                            System.Management.Automation.TypeAcc…

As you can see , there is a lot of them!

you can even create your own. Read this blog post

On of the cooler ones is [adsisearcher].

All it need is a AD query as input I you will have the result in the variable.

Actually if you are familiar with .net programming, you know that types in .net is named fx:

[System.Net.NetworkInformation.IPStatus]

 

Thanks to the great forum reply about this subject, you can read it here: http://stackoverflow.com/questions/1145312/where-can-i-find-a-list-of-powershell-net-type-accelerators

By | 2012-02-09T13:15:03+00:00 February 9th, 2012|Powershell, Scripting & Development|2 Comments

About the Author:

Jakob Gottlieb Svendsen

Twitter: @JakobGSvendsen

Jakob Gottlieb Svendsen is a Microsoft Cloud and Data Center Management MVP (http://mvp.microsoft.com/en-us/default.aspx), Working as Global Lead Developer, Senior Consultant and Trainer at CTGlobal, where he is one of the driving forces in keeping CTGlobal a System Center Gold Partner and member of the System Center Alliance.

Since he started at Coretech in 2007, he has focused on Scripting and Development, primarily developing tools, extensions and scripts for the System Center Suite. His main area is Automation (including OMS/Azure Automation, Service Management Automation, PowerShell and Orchestrator). Another area is Windows Azure Pack / Azure Stack, where he does implementation, development, workshops and presentations. He is a world-wide renowned voice in the Automation field.

He is passionately devoted to the community, to which he contributes by being a moderator at TechNet and sharing his knowledge at https://blog.ctglobalservices.com/jgs

  • Co-founder: PowerShell User Group Denmark
  • Speaker at MMS 2016, Minneapolis (www.mmsmoa.com)
  • SCU Europe 2014, 2015, 2016 (www.systemcenteruniverse.ch)
  • Microsoft TechEd North America 2014, Houston
  • NIC 2012,2013,2014,2015, Oslo (www.nic.com)
  • Microsoft CampusDays 2011, 2013, Copenhagen
  • Microsoft TechDays 2015, Sweden (www.techdays.se)
  • Microsoft Partner Event: New in SC2012 SP1
  • User group meetings (PSUG.DK , SCUG.DK/BE/NO, AZMUG + more)
  • Microsoft Certified Trainer.
  • Microsoft Scripting Guys Forum Moderator

Main working areas:

  • Automation (Azure Automation, SMA, SCO)
  • Windows Azure Pack / Azure Stack
  • System CenterVisual Studio Team Services / Team Foundation Server
  • Development:C#.Net, VB.NET, VBScript, PowerShell, Service Manager, OpsMgr, ConfigMgr
  • Orchestrator
  • Windows Azure Pack / Azure Stack

Training:

  • Azure Automation
  • Service Management Automation
  • System Center Orchestrator
  • PowerShell, VBScript, C#.Net, VB.Net
  • Windows Azure Pack / Azure Stack Development Workshops

2 Comments

  1. Ernie August 1, 2012 at 17:51 - Reply

    Exactly what I was looking for,

    Thanks for posting Jacob

    Regards
    Ernie

  2. Bekki September 25, 2014 at 17:07 - Reply

    Great article Jacob! We’ve recently written a blog on PowerShell Type Accelerators – shortcuts to .NET classes that might be of interest:
    http://www.ravn.co.uk/powershell-type-accelerators-shortcuts-dotnet-classes/

    Would be good to hear your thoughts.

Leave A Comment