3

I want to create a new alias in Powershell, but doing the following:

new-alias -name dog -value "C:\Path\To\Dog.exe -flag1 -flag2 arg3"

gives me an error about "C:\Path\To\Dog.exe -flag1 -flag2 arg3" not being a valid cmd. I also tried the following:

new-alias -name dog -value "C:\Path\To\Dog.exe" -flag1 -flag2 arg3

but this caused PS to complain that "-flag1" was not a valid option for the new-alias command. How do I pass parameters in my alias, like I can do in *nix-land?

xdhmoore
  • 8,935
  • 11
  • 47
  • 90

2 Answers2

1

One way to do this is to create a function that accepts all the parameters you want for your app and then alias that.

function Get-Ipconfig
{
    param
    ($Parameter1 = 'all')

    ipconfig.exe "`/$parameter1"

}


Get-Ipconfig

New-Alias -Name gip -Value Get-Ipconfig
Kiran Reddy
  • 2,836
  • 2
  • 16
  • 20
-2

Try putting your command inside brackets:

new-alias -name dog -value (&"C:\Path\To\Dog.exe" -flag1 -flag2 arg3)
xXhRQ8sD2L7Z
  • 1,686
  • 1
  • 14
  • 16