Wednesday, 3 December 2014

Remove-TypeAccelerator

<#
.SYNOPSIS
This script removes a type accelerator from your system
.DESCRIPTION
This script removes a NEW TA from your system.
.NOTES
File Name : Remove-TypeAccelerator.ps1
Author : Thomas Lee - tfl@psp.co.uk
Requires : Version 3
.LINK
Script Repository
http://www.pshscripts.blogspot.com
.Example
Psh[C:\foo]> Remove-TypeAccelerator tfl
Alias [tfl] removed
#>

###
# Start of script
###

Function Remove-TypeAccelerator {
[cmdletbinding()]
param (
[Parameter(Mandatory=$true)]
[string] $alias
)

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

# Return
"Alias [$alias] removed"
}

Set-Alias rta Remove-TypeAccelerator

# Test this out
Remove-TypeAccelerator 'foo3'

No comments: