# Set-Alias

**URL:** <https://forums.powershell.org/t/set-alias/14484>\
**Category:** PowerShell Help\
**Created:** [June 4, 2020, 6:49pm UTC](https://forums.powershell.org/t/set-alias/14484 "2020-06-04T18:49:15Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![trgrassijr](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@trgrassijr](https://forums.powershell.org/u/trgrassijr)\
**Post date:** [June 4, 2020, 6:49pm UTC](https://forums.powershell.org/t/set-alias/14484/1 "2020-06-04T18:49:15Z")

</div>

```auto
Set-alias -Name esxi11 -Value Connect-VIServer -Server ESXI-11 -user root -password " ***********"

```

Set-Alias : A parameter cannot be found that matches parameter name ‘Server’.  
At line:1 char:48

- Set-alias -Name esxi11 -Value Connect-VIServer -Server ESXI-11 -u …
- 

```
                                           ~~~~~~~

```

  - CategoryInfo : InvalidArgument: (🙂 [Set-Alias], ParameterBindingException
  - FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.SetAliasCommand

If I pace quotes around the command it saves it

but will not run

PS C:\util\> esxi11 esxi11 : The term ‘Connect-VIServer -Server ESXI-11 -user root -password “\*\*\*\*\*\*\*\*\*\*\*\*”’ 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

- esxi11
- 

```auto
  + CategoryInfo : ObjectNotFound: (Connect-VIServe...ord "##My95hog":String) [], CommandNotFoundException
  + FullyQualifiedErrorId : CommandNotFoundException

```

Any ideas?

Thank you

Tom

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [June 4, 2020, 7:38pm UTC](https://forums.powershell.org/t/set-alias/14484/2 "2020-06-04T19:38:20Z")

</div>

Is it your “I’m trying to do the impossible” - day? 😉😃

You cannot provide a complex command including the parameters and values to the parameter **-Value** of **Set-Alias** or **New-Alias**.

You may take a look at [$PSDefaultParameterValues](https://learn-powershell.net/2013/12/11/using-psdefaultparametervalues-in-powershell/). But anyway - you should not at all store your passwords in such a way as it is highly insecure.

---

<div class="post-metadata">

**Author:** ![trgrassijr](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@trgrassijr](https://forums.powershell.org/u/trgrassijr)\
**Post date:** [June 4, 2020, 8:05pm UTC](https://forums.powershell.org/t/set-alias/14484/3 "2020-06-04T20:05:40Z")

</div>

Olaf

Why not an Alias command is suppose to help you with making your life simpler with out typing out a long command line.

I do not see how $PSDefaultParameterValuses can help

Also it does not work even if I leave off the -user and the -password

This should work like scriptblock does

---

<div class="post-metadata">

**Author:** ![andysvints](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/andysvints/32/1017_2.png) [@andysvints](https://forums.powershell.org/u/andysvints)\
**Post date:** [June 4, 2020, 8:28pm UTC](https://forums.powershell.org/t/set-alias/14484/4 "2020-06-04T20:28:41Z")

</div>

Hello Tom,

You can create alias for cmdlet or executable but not for cmdlet with some arguments.

In order to accomplish what you are describing you should use function.

```
Function CD32 {
Set-Location -Path C:\Windows\System32
}
PS> Set-Alias -Name Go -Value CD32
```

In your case it will be something like

```
Function esxi11 {
Connect-VIServer -Server Esxi11 ...
}
```

Reference:

> **[Set-Alias (Microsoft.PowerShell.Utility) - PowerShell](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/set-alias?view=powershell-7)**
>
> The Set-Alias cmdlet creates or changes an alias for a cmdlet or a command, such as a function, script, file, or other executable. An alias is an alternate name that refers to a cmdlet or command. For example, sal is the alias for the Set-Alias...

Hope that helps.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [June 4, 2020, 8:34pm UTC](https://forums.powershell.org/t/set-alias/14484/5 "2020-06-04T20:34:18Z")

</div>

> [@](#):
>
> Why not an Alias command is suppose to help you with making your life simpler with out typing out a long command line.

Hmmm yes and no. An alias is a shorter version of the command. Not the command including parameters and values. For example **gci** is short for **Get-ChildItem**.

> [@](#):
>
> I do not see how $PSDefaultParameterValuses can help

I expected this. 😉 Did you read the information in the link I posted? You could set **-Server ESXI-11** as the _default paramete_r for **Connect-VIServer**. When you additionally create an **alias** for **Connect-VIServer** with the name **esxi** you wouldn’t have to type that much anymore … only the password would be needed then. 😉

> [@](#):
>
> This should work like scriptblock does

You should complain this to the MS Powershell team. 😉

**Edit:**  
You still could create a function with everything you want in it.

---

<div class="post-metadata">

**Author:** ![trgrassijr](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@trgrassijr](https://forums.powershell.org/u/trgrassijr)\
**Post date:** [June 4, 2020, 8:58pm UTC](https://forums.powershell.org/t/set-alias/14484/6 "2020-06-04T20:58:57Z")

</div>

Olaf,

I am new to this $PSdefaultParameterValues command

PS C:\util\> $PSDefaultParameterValues.Add({“ESXI11”})

Cannot find an overload for “Add” and the argument count: “1”.  
At line:1 char:1

- $PSDefaultParameterValues.Add({“ESXI11”})
- 

```auto
  + CategoryInfo : NotSpecified: (:) [], MethodException
  + FullyQualifiedErrorId : MethodCountCouldNotFindBest

```

I should be able to do this then if I get the $PSdefaultParameterVaules set right

Set-alias -Name vc1 -Value Connect-VIServer $PSdefaultParametersVaules

An example would be great

Thank you

Tom

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [June 5, 2020, 12:28am UTC](https://forums.powershell.org/t/set-alias/14484/7 "2020-06-05T00:28:04Z")

</div>

All of the answers and examples are in the docs and blog posts everywhere. You’ve been told several times you can’t save arguments in an alias yet you keep trying. You could potentially save it all like you want in a variable (with parameters, an anonymous function) but that’s very advanced in comparison to the commands you’re already struggling with. I feel you would have a lot more success, and therefore a lot more enjoyment, if you slow down and actually learn how powershell and these Cmdlets work. Read and play around. Break things down into smaller chunks. Best of luck Tom.

---

<div class="post-metadata">

**Author:** ![trgrassijr](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@trgrassijr](https://forums.powershell.org/u/trgrassijr)\
**Post date:** [June 5, 2020, 7:09am UTC](https://forums.powershell.org/t/set-alias/14484/8 "2020-06-05T07:09:32Z")

</div>

Guys

I got it working now found nice video with examples of how to use $PSdefaultParameters

$PSDefaultParameterValues =@{“Connect-VIServer:Server”=“ESXI11”}  
Set-alias -Name vc1 -Value Connect-VIServer

Now when I type vc1 I get prompted for my credentials which is great.

Just one other question on this.  
I have several servers ESXI11 ESXI12 ESXI13 etc.

Any thoughts On how I can setup those When you run $PSDefaultParmeterValues it overlays the previous one if using the same cmdletname

Thanks  
Tom

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [June 5, 2020, 7:56am UTC](https://forums.powershell.org/t/set-alias/14484/9 "2020-06-05T07:56:08Z")

</div>

> [@](#):
>
> Any thoughts On how I can setup those When you run $PSDefaultParmeterValues it overlays the previous one if using the same cmdletname

That’s the disadvantage for this case … it’s the DEFAULT.

But I mentioned it before and others as well … you could create functions for this. One function for each server.

---

<div class="post-metadata">

**Author:** ![trgrassijr](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@trgrassijr](https://forums.powershell.org/u/trgrassijr)\
**Post date:** [June 5, 2020, 9:00am UTC](https://forums.powershell.org/t/set-alias/14484/10 "2020-06-05T09:00:35Z")

</div>

Olaf,

Functions was the answer the work great.

Thank you

On to more powershell

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:29pm UTC](https://forums.powershell.org/t/set-alias/14484/11 "2024-05-16T20:29:36Z")

</div>

Closed on May 16, 2024, 8:29pm UTC


