#requires -version 2.0 # ----------------------------------------------------------------------------- # Script: Convert-AllDefinition.ps1 # Version: 1.0 # Author: Jeffery Hicks # http://jdhitsolutions.com/blog # http://twitter.com/JeffHicks # Date: 4/7/2011 # Keywords: ISE, Alias, Command, Regex, Pattern # Comments: # converts all command aliases in selected text to their corresponding command # definition. # # "Those who forget to script are doomed to repeat their work." # # **************************************************************** # * DO NOT USE IN A PRODUCTION ENVIRONMENT UNTIL YOU HAVE TESTED * # * THOROUGHLY IN A LAB ENVIRONMENT. USE AT YOUR OWN RISK. IF * # * YOU DO NOT UNDERSTAND WHAT THIS SCRIPT DOES OR HOW IT WORKS, * # * DO NOT USE IT OUTSIDE OF A SECURE, TEST SETTING. * # **************************************************************** # ----------------------------------------------------------------------------- Function ConvertTo-Definition { [cmdletbinding()] Param( [Parameter(Position=0,Mandatory=$True,HelpMessage="Enter a string to convert from an alias to a command")] [string]$Text ) #Verify we are in the ISE if ($host.name -match "ISE") { Write-Verbose "Getting aliases" $aliases=get-alias | where {$_.name -notmatch "\?|\%"} foreach ($alias in $aliases) { #match any alias on a word boundary that doesn't start with a $ or #has a - before or after it. if ($Text -match "(m?)(?<=\b)(?