Monday, 1 December 2014


    This script defines a function to get a list of
    Type Accelerators in PowerShell and displays them nicely
    This script gets the details of type accelerators in the system. 
    Earlier versions of this script uses a different class, which
    has been taken private and is not available any more. This 
    script also creates an alias for the function. GTA takes a
    string parameter which is used as a regular expression to 
    find a subset of type accelerators.
    Additional Notes, eg
    File Name  : Get-TypeAccelerator.ps1
    Author     : Thomas Lee -
    Requires   : Version 3
    Original article:
    Script Repository
    Psh[C:\foo]>Get-TypAccelerator int
     Name   Type                      
    ----   ----                      
    bigint System.Numerics.BigInteger
    int    System.Int32              
    int16  System.Int16              
    int32  System.Int32              
    int64  System.Int64              
    uint16 System.UInt16             
    uint32 System.UInt32             
    uint64 System.UInt64       

    Psh[C:\foo]>Get-TypAccelerator 's$'
    Name              Type                                                   
    ----              ----                                                   
    Alias             System.Management.Automation.AliasAttribute            
    cimclass          Microsoft.Management.Infrastructure.CimClass           
    ipaddress         System.Net.IPAddress                                   
    mailaddress       System.Net.Mail.MailAddress                            
    SupportsWildcards System.Management.Automation.SupportsWildcardsAttribute
    wmiclass          System.Management.ManagementClass    

#   Start of script
Function Get-TypeAccelerator {
param (
  [string] $accelerator

([PSObject].Assembly.GetType("System.Management.Automation.TypeAccelerators")::Get).getenumerator() |
  Select-object @{Name="Name"; expression={$_.key}},  
                @{name="Type"; expression={$_.value}} | 
  where name -match $accelerator | Sort name | Format-Table -Autosize
Set-Alias gta Get-TypAccelerator

# Test script
Get-TypAccelerator  int  # anything with int 
Get-TypeAccelerator 's$' # ends in s

No comments: