Create dynamic alias for Powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$aliasFilePath = "<Alias file path>" | |
function New-CommandAlias { | |
param( | |
[parameter(Mandatory=$true)]$CommandName, | |
[parameter(Mandatory=$true)]$Command, | |
[parameter(Mandatory=$true)]$CommandAlias | |
) | |
$functionFormat = "function $commandName { & $command $args } | |
New-Alias -Name $commandAlias -Value $commandName -Force -Option AllScope" | |
$newLine = [Environment]::NewLine | |
Add-Content -Path $aliasFilePath -Value "$newLine$functionFormat" | |
Write-Host "Successfully created new alias" | |
} | |
. $aliasFilePath |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Create dynamic alias commands to update https://gist.github.com/rahulpnath/8a6413dadf8759ffbc9778d018ab2039. This allows to add more commands to the file dynamically from PowerShell itself
Sample Usage: