<#
.SYNOPSIS
This function 'measures' (counts) the number of
Type Accelerators on your system.
.DESCRIPTION
This function counts the number of type accelerators are
on your systems and returns that number.
.NOTES
File Name : Measure-TypeAccelerator.ps1
Author : Thomas Lee - tfl@psp.co.uk
Requires : Version 3
.LINK
Script Repository
http://www.pshscripts.blogspot.com
.Example
Psh[C:\foo]> Measure-TypeAccelerator.ps1
84
.Example
Psh[C:\foo]> Count-TypeAccelerator.ps1
84
#>
Function Measure-TypeAccelerator {
# Define parameters and enable advanced functions
# NB no parameters!
[cmdletbinding()]
Param ()
# Start of function
Write-Verbose 'Getting acount of all Type Accelerators'
$Count = (([PSObject].Assembly.GetType('System.Management.Automation.TypeAccelerators')::Get).GetEnumerator() |
Measure).count
Write-Verbose "$Count Type Accelerators found on $(hostname)"
Return $count
}
# Set an alias
Set-Alias CTA Measure-TypeAccelerator
Set-Alias MTA Measure-TypeAccelerator
This blog contains PowerShell scripts, more PowerShell scripts and still more PowerShell scripts. Occasionally you may see some organisational posts.
Thursday, 4 December 2014
Measure-TypeAccelerator.ps1
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'
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
Monday, 1 December 2014
Get-TypeAccelerator.ps1
<# .SYNOPSIS This script defines a function to get a list of Type Accelerators in PowerShell and displays them nicely .DESCRIPTION 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. .NOTES Additional Notes, eg File Name : Get-TypeAccelerator.ps1 Author : Thomas Lee - tfl@psp.co.uk Requires : Version 3 .LINK Original article: http://www.nivot.org/2008/12/25/ListOfTypeAcceleratorsForPowerShellCTP3.aspx Script Repository http://www.pshscripts.blogspot.com .Example 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 .Example 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 { [Cmdletbinding()] 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
Subscribe to:
Posts (Atom)