Reputation: 2073
I tried to set an alias in PowerShell by running Set-Alias -Name artisan -Value 'php aritsan'
, though the command ran successfully but when I call the alias the following error occurs :
artisan : The term 'php aritsan' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At line:1 char:1
+ artisan
+ ~~~~~~~
+ CategoryInfo : ObjectNotFound: (php aritsan:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
What's the correct way to go for?
P.S: artisan
is a file in the current directory. The file is packaged with laravel framework
Upvotes: 3
Views: 3203
Reputation: 41
if (!(Test-Path -Path $PROFILE )) {New-Item -Type File -Path $PROFILE -Force }
then notepad $profile
in notepad past this code:
function art($arg1,$arg2,$arg3,$arg4,$arg5) { php artisan $arg1 $arg2 $arg3 $arg4 $arg5} Set-Alias a art
Upvotes: 0
Reputation: 839
All the details are described in:
Get-Help alias -ShowWindow
shows all available help for alias
Get-Help Set-Alias
show specific help for Set-Alias
An alias is an alternate name or nickname for a cmdlet or for a command element, such as a function, script, file, or executable file. You can use the alias instead of the command name in any Windows PowerShell commands.
You can assign an alias to a cmdlet, script, function, or executable file.
However, you cannot assign an alias to a command and its parameters.
For example, you can assign an alias to the Get-Eventlog cmdlet, but you
cannot assign an alias to the "Get-Eventlog -LogName System
" command.
However, you can create a function that includes the command. To create a function, type the word "function" followed by a name for the function. Type the command, and enclose it in braces ({}).
For example, the following command creates the syslog function. This
function represents the "Get-Eventlog -LogName System
" command:
function syslog {Get-Eventlog -LogName System}
You can now type "syslog" instead of the command. And, you can create aliases for the syslog function.
For more information about functions, type:
Get-Help about_Functions
Upvotes: 0
Reputation: 267
This will help you create an alias for "php artisan" in Windows PowerShell Globally. Just follow these steps and its done.
First of all search powershell using win+S and run it as administrator and then paste this code and hit Enter.
if (!(Test-Path -Path $PROFILE )) {New-Item -Type File -Path $PROFILE -Force }
Then run this command.
notepad $profile
A notepad file will open. Paste this code in notepad file and hit ctrl+S
Function CD32($arg1,$arg2,$arg3,$arg4,$arg5) {php artisan $arg1 $arg2 $arg3 $arg4 $arg5} Set-Alias -Name pa -Value CD32
And then finally paste this command on your powershell and hit enter.
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
And it's done. Now you can use "pa" as an alias for "php artisan" globally in your windows powershell.
Here I am using "pa" on my VS Code PowerShell.
Upvotes: 7