Monday, December 19, 2022

PowerShell alias with parameters?

bash/sh alias can include parameters, i.e. "alias kaf='kubectl alias -f"

PowerShell set-alias (sal) is only alias for a command/program.

Set-Alias (Microsoft.PowerShell.Utility) - PowerShell | Microsoft Learn

to include parameters would need to create a function, and store it in "profile"

 How to: Create a PowerShell alias with parameters -

function Encode-Video([string]$VideoFileName, [string]$OutputFileName)
    ffmpeg -i "$VideoFileName" -vcodec h264 -acodec mp2 "$OutputFileName"
notepad $profile

PS> function docmd { cmd /c $args there }
PS> docmd echo hello
hello there

but such function may not recognize programs from path

PowerShell Power User Tips: Bash-style “alias” command.

or just use linux shell (WSL)

No comments: