In Powershell 5.1 on Windows 10 I am trying to add an alias by calling:
New-Alias -Name k -Value "kubectl -n my-aks-namespace"
However when I try to use it by calling k get pods
it seems to me, that all the 3 words in the value of my alias are interpreted as a single string and as such the command "kubectl -n my-aks-namespace" get pods
is of course not found by Powershell, resulting in the error:
k : The term 'kubectl -n my-aks-namespace' 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
+ k get pods
+ ~
+ CategoryInfo : ObjectNotFound: (kubectl -n my-aks-namespace:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
When I just call kubectl -n my-aks-namespace get pods
without trying to use the alias, everything works and the list of pods is printed.
UPDATE:
Many thanks for your comments, I have run notepad $PROFILE
and put the following line in there:
function k { kubectl -n my-aks-namespace @args }
And now I am able to call the commands like:
k get nodes
k get pods
at my Powershell prompt. (For this to work, I had to remove my broken New-Alias
first.)