エイリアシングの混乱 - '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

間に合わせとして、存在しないコマンドを明示的に再定義することもできますvmSet-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 のコマンド命名に対する「動詞優先」アプローチの一部です。

PowerShell ではGet-、動詞が指定されていない場合、コマンドレットの動詞が自動的に想定されます。

などのコマンドをいくつか書くだけで試すことができます。childitem自動的locationに実行されGet-ChildItemGet-Location

これは、この動作について調べるために試したさまざまなコマンドレットの動作についても説明しています。

  • Get-Command vm- vm はコマンドではないため、見つかりませんでした。
  • Get-Alias vm- 別名でもないので、ここでも見つけることはできません。

この動作はユーザー定義関数やコンソールアプリケーションには適用されません。そのため、DoStuffPowerShellが自動的に実行しない関数を作成できます。Get-DoStuff

この動作を変更することはできませんが、vm本当にそうしたい場合は、何か他のことを実行する関数を作成することはできます。

関連情報