Last active
December 6, 2019 09:36
-
-
Save rahulpnath/0007a3bdd7da2efc7024bd92c002cf17 to your computer and use it in GitHub Desktop.
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: