1

I am trying to make a alias in powershell that uses name of the parameter and a file in different directory, in alias I can set the python c:\sqlmap\sqlmap.py but when I use the alias it just prints out the sqlmap first page instead of using the further parameters that sqlmap need to use

Set-Alias -Name sqlmap -Value 'python  D:\tools\sqlmap-master\sqlmap.py'

or I tried the functional loop also

function sqlmap { 
    $current_dir = (get-lcoation).location
    set-location 'D:\tools\sqlmap-master\'
    python sqlmap.py
    if ($?){
        set-location current_dir
    }
}

but none of them taking the arguments like sqlmap basic parameter is python sqlmap -u https:/web.com..... --dbs

how can I make this alias to let sqlmap independently... i want to reduce the use of going into directory and then running python sqlmap.py ...... everytime

kalalua
  • 35
  • 4
  • 1
    As for attempting to use an _alias_: Unlike in POSIX-compatible shells such as `bash`, you _cannot include pass-through arguments_ in a PowerShell alias definition - you need a _function_ for that, as shown in the accepted answer. PowerShell aliases are simply _alternative names_ for other commands, with no ability to "bake in" arguments; see [this answer](https://stackoverflow.com/a/63292585/45375). – mklement0 Sep 06 '21 at 14:05

1 Answers1

2

To pass the arguments provided, splat the $args automatic variable when invoking python:

function sqlmap {
  python D:\tools\sqlmap-master\sqlmap.py @args
}
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206