Super late answer, but I wanted to do this for all the scripts in my bin folder, and it took me a while to figure it out. I wound up with this:
Get-ChildItem -path <bin where your ps1 files live> -Filter *.ps1 |
Foreach-Object{
$name = $_.Name
$scptName = $_.Name -split ".ps1",0,"simplematch"
$scptName = $scptName[0]
new-alias $name $scptName
}
And I also wanted it for all the python scripts in my python bin, which was more complicated but still doable:
Get-ChildItem -path <pybin path> -Filter *.py |
Foreach-Object{
$name = $_.Name
$scptName = $_.Name -split '.py',0,'simplematch'
$scptName = $scptName[0]
$eName = $scptName -split '-',0,'simplematch'
$eName = $eName[1]
invoke-expression('
$val' + $eName + ' = $name
function doRun' + $eName + '{
python "<pybin path>/$val' + $eName + '" $args
}
$alias = "doRun$ename"
set-alias $scptName $alias
')
}
Note that you are invoke-expressioning on an expression containing filenames on your system, so this is a security problem if other people can potentially write to that directory. Since this is my bin directory and I'm execing this stuff all the time anyways I've decided it doesn't matter, but it could so keep that in mind.
There's also certainly a more elegant way to have accomplished this, but I wasn't sure what it was.