Confusión de alias: ¿qué asignó 'vm' a 'Get-VM'?

Confusión de alias: ¿qué asignó 'vm' a 'Get-VM'?

Con la intención de lanzar vim desde este

PS C:\temp> get-command vim | select name,source

Name    Source
----    ------
vim.bat C:\Users\noam\AppData\Local\Microsoft\WindowsApps\vim.bat

Entré accidentalmente vmen lugar de vimy me quedé con muchas dudas:

C:\temp>pwsh -noprofile
PowerShell 7.4.1
PS C:\temp> vm
Get-VM: 29-Mar-24 16:28:14      Get-VM          You are not currently connected to any servers. Please connect first using a Connect cmdlet.
PS C:\temp> get-command vm
Get-Command: The term 'vm' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
PS C:\temp> get-alias vm
Get-Alias: This command cannot find a matching alias because an alias with the name 'vm' does not exist.
PS C:\temp> cmd /c where vm
INFO: Could not find files for the given pattern(s).

¿Cómo encontrar y eliminar la configuración que aparentemente se ha asignado vmdesde Get-VMPowerCLI de VMware?

PS C:\temp> get-command get-vm | select Name,Source

Name   Source
----   ------
Get-VM VMware.VimAutomation.Core

Debo estar perdiendo algo tonto. Pensé que la llamada anterior where.exedebería haber descubierto algo relevante en mi camino. De todos modos, el comportamiento no cambia después de la configuración $env:PATH = $null.

Como una pifia, podría redefinir explícitamente vmvía Set-Aliasalgún comando inexistente. Pero me gustaría entender por qué no veo algo como lo siguiente al ejecutar vm. ¿Qué he pasado por alto?

PS C:\temp> doesnotexist
doesnotexist: The term 'doesnotexist' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Los resultados anteriores han sido reproducibles con y sin el VMware.VimAutomation.Coremódulo importado explícitamente.

Respuesta1

Esto no es un "problema de alias", es parte del enfoque de "primero el verbo" de PowerShell para la denominación de comandos.

PowerShell asume automáticamente el Get-verbo en los cmdlets cuando no se especifica ningún verbo.

Puedes probarlo simplemente escribiendo algunos comandos como childitem, locationetc., se ejecutará automáticamente Get-ChildItemyGet-Location

Esto también explica los comportamientos de los diferentes cmdlets que intentó averiguar sobre este comportamiento:

  • Get-Command vm- Como vm no es el comando, no se encontró.
  • Get-Alias vm- Como tampoco es un alias, tampoco podrás encontrarlo aquí.

Este comportamiento no se aplica a funciones definidas por el usuario ni a aplicaciones de consola, por eso puede crear funciones llamadas DoStuffy PowerShell no lo hará automáticamente.Get-DoStuff

No puedes cambiar este comportamiento, pero puedes crear una vmfunción que haga otra cosa, si realmente quieres hacerlo.

información relacionada