簡體   English   中英

PowerCLI 有一個隱藏的 vc 別名,我不知道它來自哪里以及是否還有更多類似的東西

[英]PowerCLI has an hidden vc alias, I can't figure where it comes from and whether there's more of its like

幾年前,我無意中在 VMware PowerCLI 中偶然發現了一個“隱藏”的 PowerShell 別名vc ,它可以用來代替Connect-ViServer 這個vc命令對Get-CommandGet-Alias都是不可見的,它不能被命令完成識別(不是你真的需要它),我只能通過它的輸出和行為將它與Connect-ViServer相關聯。

我發現這個特定的偽別名在我的 PowerCLI 工作中非常有用,我一直想知道它是如何工作的,以及是否還有其他這樣的隱藏快捷方式。 今天,我在我的系統中搜索了 Get-Command 未知的 2 字母和 3 字母命令,在vc旁邊出現的唯一命令是縮短的 Get-* 命令(如下面的 @vrdse 所述)。

  1. 誰能解釋一下這個vc偽別名是在哪里/如何定義的?
  2. 如何比使用以下腳本或純粹靠運氣更有效地找到類似的隱藏命令?

這是我的三字母別名的(快速而骯臟的)腳本,它在我的系統上運行了大約一個小時(!),除了縮短的 Get-* 命令之外什么也沒找到:
(注意:不建議像我一樣盲目地運行隨機命令)

$az = [char[]]('a'[0]..'z'[0])
foreach ($i in $az) {
    write $i
    foreach ($j in $az) {
        write $i$j
        foreach ($k in $az) {
            if (!(gcm -ea ig $i$j$k)) {
                try {iex $i$j$k; write-warning $i$j$k} catch {}
            }
        }
    }
}

正如我在評論中已經說過的,PowerShell 不需要Get- of Get-*命令,例如Get-Vhd 相反,您可以只輸入Vhd 話雖如此,您可以檢查Connect-ViServer別名。

Get-Alias -Definition Connect-ViServer
-----------     ----        
Alias           Get-ESX     
Alias           Get-VC      
Alias           Get-VIServer

你看,事實上它有一些別名。 其中之一是Get-VC ,因此vc是可能的。

從理論上講,這應該有效。 我不知道為什么它不顯示像“dir”這樣的常見別名(是的,它們是在引擎https://github.com/PowerShell/PowerShell/issues/8970中定義的):

get-module -ListAvailable | select name,exportedaliases

哦,Powershell,你是如此多變和神秘。 ExportedAliases 似乎沒有多大用處。

gcm get-vc

CommandType     Name       Version    Source
-----------     ----       -------    ------
Alias           Get-VC     11.5.0.... VMware.VimAutomation.Core


get-module VMware.VimAutomation.Core | select name, exportedaliases

Name                      ExportedAliases
----                      ---------------
VMware.VimAutomation.Core {}

別名似乎是在模塊文件shrug中導出的。 VMware.VimAutomation.Core.psd1,第 46 行。

PS C:\Users\js\Documents\WindowsPowerShell\Modules> ls -r * | select-string get-vc

VMware.VimAutomation.Core\11.5.0.14899560\net45\VMware.VimAutomation.Core.ps1:145:set-alias Get-VC Connect-VIServer
-Scope Global
VMware.VimAutomation.Core\11.5.0.14899560\netcoreapp2.0\VMware.VimAutomation.Core.ps1:145:set-alias Get-VC
Connect-VIServer -Scope Global
VMware.VimAutomation.Core\11.5.0.14899560\VMware.VimAutomation.Core.psd1:46:AliasesToExport = @('Answer-VMQuestion','Ap
ply-DrsRecommendation','Apply-VMHostProfile','Export-VM','Get-ESX','Get-PowerCLIDocumentation','Get-VC','Get-VIServer',
'Get-VIToolkitConfiguration','Get-VIToolkitVersion','Set-VIToolkitConfiguration','Shutdown-VMGuest')

我是這樣得到的。

Get-Command -Module VMware.VimAutomation.Core -CommandType Alias

CommandType Name                       Version         Source
----------- ----                       -------         ------
Alias       Answer-VMQuestion          11.5.0.14899560 VMware.VimAutomation.Core
Alias       Apply-DrsRecommendation    11.5.0.14899560 VMware.VimAutomation.Core
Alias       Apply-VMHostProfile        11.5.0.14899560 VMware.VimAutomation.Core
Alias       Export-VM                  11.5.0.14899560 VMware.VimAutomation.Core
Alias       Get-ESX                    11.5.0.14899560 VMware.VimAutomation.Core
Alias       Get-PowerCLIDocumentation  11.5.0.14899560 VMware.VimAutomation.Core
Alias       Get-VC                     11.5.0.14899560 VMware.VimAutomation.Core
Alias       Get-VIServer               11.5.0.14899560 VMware.VimAutomation.Core
Alias       Get-VIToolkitConfiguration 11.5.0.14899560 VMware.VimAutomation.Core
Alias       Get-VIToolkitVersion       11.5.0.14899560 VMware.VimAutomation.Core
Alias       Set-VIToolkitConfiguration 11.5.0.14899560 VMware.VimAutomation.Core
Alias       Shutdown-VMGuest           11.5.0.14899560 VMware.VimAutomation.Core

或者

alias | ? source -match vmware

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM