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

349 Views Asked by At

A few years ago, I accidently stumbled upon an "hidden" PowerShell alias in VMware PowerCLI, vc, which can be used instead of Connect-ViServer. This vc command is invisible to both Get-Command and Get-Alias, it's not recognized by command completion (not that you really need it to), and I could only relate it to Connect-ViServer by its output and behavior.

I found this specific pseudo-alias to be pretty useful in my PowerCLI work, and I always wondered how this worked, and whether there were other such hidden shortcuts. Today, I searched my system for 2-letter and 3-letter commands unknown to Get-Command, and the only ones that came out beside vc were shortened Get-* commands (as explained by @vrdse below).

  1. Can anyone explain where/how this vc pseudo-alias is defined ?
  2. How can I find similar hidden commands more efficiently than with the below script or by sheer luck ?

Here's my (quick and dirty) script for 3-letter aliases, which ran for about an hour (!) on my system, and found nothing but shortened Get-* commands :
(Caution: blindly running random commands as I did is NOT recommended)

$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 {}
            }
        }
    }
}
2

There are 2 best solutions below

1
vrdse On BEST ANSWER

As I stated already in the comments, PowerShell doesn't require the Get- of Get-* commands, such as Get-Vhd. Instead, you can just type Vhd. That being said, you can check for aliases for Connect-ViServer.

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

You see, that in fact there are some aliases to it. One of which is Get-VC, thus vc is possible.

3
js2010 On

Theoretically, this should work. I don't know why it doesn't show common aliases like "dir" (yes they are defined in the engine https://github.com/PowerShell/PowerShell/issues/8970):

get-module -ListAvailable | select name,exportedaliases

Oh Powershell, you are so varied and mysterious. ExportedAliases doesn't seem to be much use.

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 {}

It seems like the aliases are exported in the module file, shrug. VMware.VimAutomation.Core.psd1, line 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')

I got it this way.

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

Or

alias | ? source -match vmware