앨리어싱 혼란 - 'vm'을 'Get-VM'에 매핑한 것은 무엇입니까?

앨리어싱 혼란 - 'vm'을 'Get-VM'에 매핑한 것은 무엇입니까?

이것에서 vim을 시작하려고합니다

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

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

나는 실수 vm로 대신에 들어갔고 vim많은 머리 긁힘이 발생했습니다.

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).

VMware의 PowerCLI에서 vm매핑 된 것처럼 보이는 구성을 찾고 제거하는 방법은 무엇입니까 ?Get-VM

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

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

나는 어리석은 것을 놓치고 있음에 틀림 없다. 나는 위의 호출이 where.exe내 경로와 관련된 모든 것을 밝혀냈어야 한다고 생각했을 것입니다 . 어쨌든 설정 후에는 동작이 변경되지 않습니다 $env:PATH = $null.

kludge로서 나는 존재하지 않는 명령을 vm통해 via를 명시적으로 재정의할 수 있었습니다. Set-Alias그런데 왜 실행할 때 아래와 같은 내용이 보이지 않는지 알고 싶습니다 vm. 내가 무엇을 간과했는가?

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.

위의 결과는 명시적으로 가져온 모듈을 사용하거나 사용하지 않고 재현 가능했습니다 VMware.VimAutomation.Core.

답변1

이는 "별칭 문제"가 아니며 명령 명명에 대한 PowerShell의 "동사 우선" 접근 방식의 일부입니다.

Get-동사가 지정되지 않은 경우 PowerShell은 자동으로 cmdlet에서 동사를 가정합니다 .

등과 같은 몇 가지 명령을 간단히 작성하여 시도해 볼 수 있습니다 childitem. location자동으로 실행 Get-ChildItem되고Get-Location

또한 이 동작에 대해 알아내려고 시도한 다양한 cmdlet의 동작에 대해 설명합니다.

  • Get-Command vm- vm은 명령어가 아니기 때문에 찾을 수 없습니다.
  • Get-Alias vm- 별칭도 아니기 때문에 여기에서도 찾을 수 없습니다.

이 동작은 사용자 정의 함수나 콘솔 응용 프로그램에는 적용되지 않습니다. 따라서 호출되는 함수를 만들 수 있지만 DoStuffPowerShell은 자동으로 수행하지 않습니다.Get-DoStuff

이 동작을 변경할 수는 없지만 vm정말로 원하는 경우 다른 작업을 수행하는 함수를 만들 수 있습니다.

관련 정보