Tuesday 2 December 2014

New-TypeAccelerator.ps1

<#
.SYNOPSIS
This script creates a new type accelerator on your system
.DESCRIPTION
This script adds a NEW TA to your system.
.NOTES
File Name : New-TypeAccelerator.ps1
Author : Thomas Lee - tfl@psp.co.uk
Requires : Version 3
.LINK
Script Repository
http://www.pshscripts.blogspot.com
.Example
Psh[C:\foo]> New-TypeAccelerator tfl system.int32
Alias [tfl] added for type [system.int32]
#>

###
# Start of script
###

function New-TypeAccelerator {
[cmdletbinding()]
param (
[Parameter(Mandatory=$true)]
[string] $alias,

[Parameter(Mandatory=$true)]
[string] $type
)

# Start of function
Try
{
([PSObject].Assembly.GetType("System.Management.Automation.TypeAccelerators")::add($alias,$type))
}
Catch
{
Write-Error "Failed to add alias [$alias] to type [$type]"
return
}

# Return
"Alias [$alias] added for type [$Type]"
}

Set-Alias nta New-TypeAccelerator

# Test this out
New-TypeAccelerator

No comments: