Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

PowerShell ISE Convert All Aliases

Posted on April 8, 2011April 7, 2011

Yesterday I posted an article on how to convert a selected word to an alias or cmdlet. While I think there is still some value in this piecemeal approach. sometimes you want to make wholesale changes, such as when troubleshooting a script that someone else wrote that is full of cryptic aliases. I have a function you can integrate into the ISE that will convert all aliases in a block of selected text and convert them to their full cmdlet name equivalents.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

My function, ConvertTo-Definition, is designed to only work within the PowerShell ISE and assumes you want to convert all aliases to their command definitions. Personally, I don't see a reason for converting the other way in a script but you can add that functionality if you really need it.

[cc lang="Powershell"]
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)(?Convert-AllDefinition and let me know what you think.


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

2 thoughts on “PowerShell ISE Convert All Aliases”

  1. Jeffery Hicks says:
    April 8, 2011 at 12:33 pm

    Several people have commented about why I didn’t use the tokenizer. Well, my primary answer is because I’m not a developer and don’t think that way. Perhaps my result is a little more complicated but it doesn’t rely on any .NET programming knowledge. That said, someone sent me a code sample using the tokenizer and I’m working with it. I can see the advantages and ultimately you probably don’t really care how the conversion happens so I might post a revision when I find some time to thoroughly review and test.

    Of course, if you write your script with full cmdlet names to begin with, this is all moot.

  2. Pingback: Round up « Use PowerShell

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d