How can I do a alias in powershell to start notepad++ have Start notepad++ and have alias i wanna combinate that
set-alias -name notepad -value start notepad++
but i get this error
Set-Alias : A positional parameter cannot be found that accepts argument 'notepad++'. At line:1 char:1
- set-alias -name notepad -value start notepad++
-
+ CategoryInfo : InvalidArgument: (:) [Set-Alias], ParameterBindingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SetAliasCommand
tl;dr
startargument and provide the full path ofnotepad++.exeas the-Valueargument, e.g. (if this full path doesn't work for you, see below for how to discover the correct one):start(Start-Process) being able to discover the location ofnotepad++.exefor you, you must use a function ($argspasses any arguments through):Building on the helpful comments:
In PowerShell, an alias is simply another name for a command (which can be a PowerShell cmdlet, function, script, or external executable, and even another alias).
Therefore,
Set-Alias's-Valueparameter only accepts a single argument to describe the target of the name mapping.set-alias -name notepad -value start notepad++is therefore broken syntax, becausenotepad++is an extra argument thatSet-Aliasdoesn't recognize.Since Notepad++ is a GUI program, there is no need to use
start(Start-Process) to launch it asynchronously, i.e. without blocking the calling session, because direct invocation does that by default (see below for a synchronous solution).Unfortunately, however, the Notepad++ installer does not include an entry in
$env:PATHfor its installation directory, hence the need to usenotepad.exe's full path above.It does, however, create a registry entry, which allows
Start-Process(as opposed to direct invocation) to discovernotepad++.exe; if you want to rely on this for simplicity, you'll need to use afunctionrather than an alias, as described below (simply remove-Waitfrom the synchronous variant).The simplest way to discover
nodepad++.exe's full path is to launch Notepad++ interactively withStart-Process -PassThruand access the.Pathproperty of the process-information object that is returned:In cases where you do need more than just another command's name or path - typically when your "alias" should include hard-coded arguments to pass to the target command - you must define a
functioninstead:Here's a variant of your "alias" - now of necessity implemented as a
function- that usesStart-Process -Waitto launch Notepad++ synchronously, i.e. in a blocking fashion, while also supporting pass-through arguments (which a true alias definition implicitly does).notepad++binds positionally to the-FilePathparameter, and$argsto the-ArgumentListparameter.$argscontains elements (if ($args)), which is - unfortunately - needed in Windows PowerShell, where a bug prevents passing an empty array to-ArgumentList; this problem has been fixed in PowerShell (Core) 7+If your alias-like function also needs to support pipeline input, see this answer.
For a more sophisticated but more complex way of wrapping other commands using so-called proxy functions, see this answer.